Sign In Register

How can we help you today?

Start a new topic
Answered

Cloud Code : Update only one field in a document with the update command?

I'm making an update to one of the documents in my collection, which has quite a large number of fields.


I want to write an event that allows me to update only one specific field in this document.


But using the update method requires that I specify all current field values as parameters, otherwise the update removes them.


 

var gameData = Spark.runtimeCollection('gameData');
gameData .update({"id":id}, {"status":status});

 


So what happens here, is the whole document is updated, but now it only has a status field, and all other fields are removed.


How do I only update the status field? I've tried setting the 'upset' parameter on update to true as well, but this makes no difference.


Best Answer

use $set

 

var gameData = Spark.runtimeCollection('gameData');
gameData.update({"id":id}, {$set:{"status":status}});

 

1 Comment

Answer

use $set

 

var gameData = Spark.runtimeCollection('gameData');
gameData.update({"id":id}, {$set:{"status":status}});

 


1 person likes this
Login to post a comment