Page 1 of 1

Can the operation $inc be used with Collection.updateObject() method

Posted: Sat May 02, 2015 11:54 pm
by apollo mcowiti

I have tried Collection.updateObject() method to try to increment a field using the $inc operations but it seems not to work. WHy?

Here is the relevant piece of code

Collection.updateObject(dbId, "theCollection", "the object id", {"$inc":{"following":1}}, masterKey);


Can the operation $inc be used with Collection.updateObject() method

Posted: Mon May 04, 2015 1:23 am
by Yurii Orishchuk

Hi Appollo,

You can not use operations methods in "updateObject" functionality.

You need to use "multiUpdateObject" instead.

Here is a working example to use operations object in update query:

pre

var collectionName = "dogs";
var dbId = "52fd3d06xxxxxxxxc89917";
var objectID = "5531be6ee4b01887fd8602a3";

var query = {"_id": objectID};

var updateObject = {
};

var operationsJSON = {
"$inc": {"number": 4}
};

var result = Collection.multiUpdateObject(dbId, collectionName, JSON.stringify(query), updateObject, operationsJSON);

response.success(result, "application/json");

/pre

Regards.