This question is locked. New answers and comments are not allowed.
Hello:
I'm trying to get the mongo $inc operator to work in cloud code using the SDK's updateSingle call, and can't even get close. A pointer to the correct syntax would be much appreciated. All I'm trying to do is increment a field called Counter in a table called MyTable when a record is added to a content type. The id of the record to update is passed in the request as "uid". The mongo update syntax doesn't seem to play well with the updateSingle syntax. Here's where I'm at now:
This logs [2014-04-14 02:06:30.868] [INFO] update failed: {"message":"Error","code":901,"name":"Request error. HTTP status code: 400"}
Thank you!
Kelly
I'm trying to get the mongo $inc operator to work in cloud code using the SDK's updateSingle call, and can't even get close. A pointer to the correct syntax would be much appreciated. All I'm trying to do is increment a field called Counter in a table called MyTable when a record is added to a content type. The id of the record to update is passed in the request as "uid". The mongo update syntax doesn't seem to play well with the updateSingle syntax. Here's where I'm at now:
Everlive.Events.afterCreate(
function
(request, response, context, done) {
if
(!response.error) {
var
options = {
Id: request.uid,
$inc: {
Counter: 1
}
};
var
n = Everlive.Sdk.withMasterKey().data(
'MyTable'
).updateSingle(options,
function
(data) {
console.log(
"update worked"
);
done();
},
function
(error) {
console.log(
"failed: "
+ JSON.stringify(error));
done();
});
}
else
{
console.log(
"calling done"
);
done();
}
});
This logs [2014-04-14 02:06:30.868] [INFO] update failed: {"message":"Error","code":901,"name":"Request error. HTTP status code: 400"}
Thank you!
Kelly