Sign In Register

How can we help you today?

Start a new topic

Accessing Document information

Hello,


I am using the following code to get an item from Meta Collection:

 var metaDataCollection = Spark.metaCollection("Collection1");


var data = metaDataCollection.find({"_id":"Menu_Stand"});


I have item like the following, how do I access to LevelDetails so I can get the displayName and cointAmount in cloud code, I want to get the value from there and assign it to player for example?


Thanks.

{
        "_id": "Menu_Stand",
        "levelDetails": [
          {
            "displayName": "Menu Stand",
            "coinAmount": 350,
          }
        ]
      }
}
1 Comment

Hi Darek, 


.find(); will return a cursor, which can be enumerated to acquire the document at that position. 

In your case you will want to use findOne, which returns an object reference. You can access fields by using dot notation i.e. 


var document = collection.findOne({"_id": "Menu_Stand"});

var object = document.levelDetails; 

var displayName = object.displayName; 


Happy to help - Patrick. 


Login to post a comment