如何使用 MongoLab Api 将 MongoDB 连接到带有 angular.js 的 Breeze.js 任何人都可以帮助连接设置。有没有人试过这个设置?
https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey
这是来自微风网站的 datacontext.js。这是 plunkr http://plnkr.co/edit/upp7wB?p=preview
app.factory('datacontext',['$http','logger', function($http, logger) {
var log = logger.log;
log("Creating datacontext");
configureBreeze();
var useLocalHost = false;
var host=useLocalHost ? "http://localhost:63428" : "http://sampleservice.breezejs.com";
var serviceName = host+"/api/todos";
var manager = new breeze.EntityManager(serviceName);
plunkerHelpers.isCorsCapable();
var datacontext = {
getAllTodos: getAllTodos,
reset: reset
};
return datacontext;
/*** supporting functions ***/
function getAllTodos() {
var query = breeze.EntityQuery.from("Todos");
log("Getting Todos");
return manager.executeQuery(query).then(success);
function success(data) {
log("Retrieved " + data.results.length);
return data.results;
}
}
function reset() {
manager.clear();
var deferred = Q.defer();
$http.post(serviceName + '/reset')
.then(resetSuccess, resetFail);
return deferred.promise;
function resetSuccess() {
log("Database reset");
deferred.resolve();
}
function resetFail() {
log("Database reset failed");
deferred.reject(new Error("Database reset failed"));
}
}
function configureBreeze() {
// configure to use the model library for Angular
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
// configure to use camelCase
breeze.NamingConvention.camelCase.setAsDefault();
}
}]);
源文件。 http://www.breezejs.com/samples/todo-angular
https://support.mongolab.com/entries/20433053-REST-API-for-MongoDB