Sign In Register

How can we help you today?

Start a new topic
Answered

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;

collections.update(
      {"playerId": Spark.getPlayer().getPlayerId()},
      {$set: 
           {
            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: 


FIELD.NESTEDFIELD


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....


https://docs.gamesparks.com/tutorials/database-access-and-cloud-storage/submitting-json-document-queries.html

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.


Thanks,

Liam

Login to post a comment