apollo mcowiti
Posts: 0
Joined: Sat Apr 18, 2015 2:21 am

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

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);

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

Return to “Issues”