angularjs-mongolab
angularjs-mongolab copied to clipboard
missing JSON.stringify in distinct function
missing JSON.stringify in distinct function at line 87
https://github.com/pkozlowski-opensource/angularjs-mongolab-promise/blob/master/src/mongolabResourceHttp.js#L87
-
var httpPromise = $http.post(dbUrl + '/runCommand', angular.extend({}, queryJson || {}, {
-
var httpPromise = $http.post(dbUrl + '/runCommand', angular.extend({}, JSON.stringify(queryJson || {}), {
@jojosati hmm, I'm not sure converting JSON to string here is the best way to go as we really want to send JSON in the POST request as data payload, with proper request headers etc.
What is the actual problem you were facing? Is it about the fact how AngularJS stringifies properties where names start with $?
@pkozlowski-opensource pardon me. It's long ago.
I think at that time If passing object data via $http.post, angular will use its own stringify function that strip out all $properties i.e. $or, $and, $in
I've not touched the mongoResource code since made it work and now wonder my final code is look like this
Resource.runCommand = function(commandJson, successcb, errorcb) {
var httpPromise = $http.post(
dbUrl + '/runCommand',
JSON.stringify(commandJson),
{
params: defaultParams,
timeout: 5 * 60 * 1000 // server overload breaker 5 minutes
});
return promiseThen(httpPromise, successcb, errorcb, function(data) {
return data.values;
});
};
Resource.distinct = function(field, queryJson, successcb, errorcb) {
return Resource.runCommand({
distinct: collectionName,
key: field,
query: queryJson || {}
}, successcb, errorcb);
};