pkozlowski-opensource / angularjs-mongolab Goto Github PK
View Code? Open in Web Editor NEWResource-like factory for MongoLab based on $http and working with promises
Home Page: http://plnkr.co/edit/Bb8GSA?p=preview
License: MIT License
Resource-like factory for MongoLab based on $http and working with promises
Home Page: http://plnkr.co/edit/Bb8GSA?p=preview
License: MIT License
Right now the getByIds function works with wrapping the provided ids in a MongoDB $oid object.
Assuming you merge my last PR this won't work in all cases. We also have to search for the bare ids.
We could either make the getByIds query a bit more complicated in order to keep the API simple:
Resource.getByIds = function (ids, successcb, errorcb) {
var qin = [];
angular.forEach(ids, function (id) {
qin.push({$oid:id});
});
return Resource.query({$or:[{id_:{$in:qin}},{id_:{$in:ids}}]}, successcb, errorcb);
};
or add another method, which queries using bare ids.
Or simply use the query method if one wants to query with bare ids.
Improving the current query would keep the API simple, but has drawback in performance.
What would you recommend?
As I spend a dynamic collection to the factory?
I'm trying some ways and still can not, I tried to pass the parameter :collection, but does not.
Any idea?
.factory('ALL', function($mongolabResourceHttp) {
//Here get the collection, pass from controller...
return $mongolabResourceHttp(COLLECTION);
})
CONTROLLER:
ALL.all(COLLECTION, { limit: 10 }).then(function(response) {
$scope.dashboardposts = response.data;
});
Thankyou for making this --- this is a real time saver. A quick example on how to use the instance level methods here would be very helpful to me :)
resource.$id()
resource.$save(successcb, errorcb)
resource.$update(successcb, errorcb)
resource.$saveOrUpdate(successcb, updateSuccesscb, errorcb, updateErrorcb)
resource.$remove(successcb, errorcb)
For example if I have a given $oid
how could I directly update that record or delete it? How do I directly add a new record to a collection?
I have been having some success using this module to help streamline my database interactions, so far so good.
I am getting a query resource to read as expected. The managers object gets passed into my template $scope and the log shows a "read success" message - Good.
In wanting to next deal with error conditions, I find that passing in a known bad ID still takes the same path to the successCB, the errorCB should fire but does not. Have I set this up wrong or made a wrong assumption? Thanks.
.controller('ContactCtrl', function($scope, $rootScope, $log, ManagersCollection) {
var criteriaObject = { im_id: "alang" };
var sortObject = { sort: { _id: 1 } };
var successCB = function(managers) {
$scope.manager = managers[0]; // use [0] for the first selected item.
$log.log( "Managers ID " + criteriaObject.im_id + " read success" );
};
var errorCB = function(managers) {
throw new Error(criteriaObject.im_id + ' item read went wrong...');
};
ManagersCollection.query(
criteriaObject,
sortObject,
successCB,
errorCB
);
})
I have a need to take data entered into the form and do calculations on it then push the result into the model as well as the original values. The problem I'm having is that I get an error when trying to save or saveOrUpdate to my mongolab db. It appears that if I mess with the model it removes all the methods you've created. Can what I need to do be done with this or will I need to dig into the MongoLab API and go server-side from the beginning?
To demonstrate I'm taking the Name & Site and concatenating them and pushing the result into the model: http://plnkr.co/edit/mfS046?p=preview
Great resource though. I like it!
Am I missing something or do I have to put my mongolab API key into the javascript that gets shipped to my users browsers?
When passing in what seems to be a perfectly good object for queryJson
such as
{"$or":[
{"attrib1": {"$regex":"some", "$options":"i"}},
{"attrib2": {"$regex":"", "$options":"i"}}
]
}
into preparyQueryParam()
, but when this runs...
angular.equals(queryJson,{}) // fragment of line 37 of mongolabResourceHttp.js
I (incorrectly) get true
๐ฑ
I looked into this and it _may_ have to do with a bug in angular when an object has an undefined value {"test":undefined}
or it may have something to do with the dollar sign $keys
needed for mongodb, I am not sure.
I am working on a fix...
Is there an example of the resource working with Angular 1.3.
I'm having an issue with adding the JSON payload to $save and $saveAndUpdate (the post request is working but it inserts an empty document into the database and I'm not sure if it's the code (copied below) or if something has changed in the way Angular works with resources.
I have a working version of this at: http://caraya.github.io/projects/#/grid
Based on the request from the mailing list, it would be easy to add the distinct
operation to the API.
thanks
included in your example for where you add the API-KEY:
app.constant('MONGOLAB_CONFIG',{API_KEY:'[your key goes here]', DB_NAME:'angularjs'});
The brackets around the api-key cause problems for me. Works fine once they're gone.
I'm not sure if I'm doing something wrong, but when I want to save my data to DB, I use following code:
Project.$saveOrUpdate().then(function(returnData){
$scope.savedData = returnData;
});
In Firefox I can't get information if data is saved successfully or not. It never executes callback function, but the data is saved.
As far as I understand, the old way of providing callback functions in .$saveOrUpdate(success, error) is not anymore valid way of getting that?
The $http service seems to interpret status code 201 (mongolab returns this) as an error. Every time I save a record both success and error callback are called.
I would suggest we handle the responses ourselves and then call the user's callback based on the status code.
Sorry if this is a very beginner question but...
Is there a way of using this in a production environment, and be able to keep your database credentials private?
I ask because this puts all the database work on the client side, right?
missing JSON.stringify in distinct function
at line 87
var httpPromise = $http.post(dbUrl + '/runCommand', angular.extend({}, queryJson || {}, {
var httpPromise = $http.post(dbUrl + '/runCommand', angular.extend({}, JSON.stringify(queryJson || {}), {
Hi,
I'm trying to use your repository...
but when loading it in the browser i'm getting below shown error...
"NetworkError: 404 Not Found - https://github.com/pkozlowski-opensource/angularjs-mongolab/blob/master/src/angular-mongolab.js."
And another is
Module 'mongolabResourceHttp' is not available
Any suggestions to slove this
Hello, a good feature would be to be able to configure different databases for different services.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.