Sign In Register

How can we help you today?

Start a new topic

Cloud Code - collection.update() -> Fieldname from Value of a Variable

 I get the name of a field that is an array as parameter:


var setName = Spark.getData().setName;

var collections = Spark.runtimeCollection("Collections");

var fieldPath = "sets." + setName;

      {"playerId": Spark.getPlayer().getPlayerId()},
            fieldPath : [0,5,7,9]
      true, // (upsert)
      false // (multi)



Now I want to update that field. The field is inside a field called "sets"....

So to access it I need to do the update on the field: 


I solved this by the fieldPath variable.

Sadly the update function never takes my variable values but only the variable name....

How do I solve this?

Best Answer

edit got it:

u can make partial queries. a query objects field can be accessed using queryobject[field] = valueOfField

this correctly reads strings from variables....

Hi Keli,

I'm glad to hear you found a solution. Thanks for sharing it. It may be useful to other users in the future. If you have any further questions just let us know.



Login to post a comment