Sign In Register

How can we help you today?

Start a new topic

Foreach using Find

 Need to iterate through every single log in a runtime collection and add 1 to the variable "acti"


 var progressCollection = Spark.runtimeCollection("Tribes");

         foreach(var d in progressCollection.find({"": ""}))
            doc.acti ++;


Getting errors on the "foreach" line. I'm not sure any of it is correct.

SparkMongoCollectionReadWrite.find() does not return an array - it returns a SparkMongoCursor.    Instead try progressCollection.find({"": ""}).toArray()

You shouldn't use toArray() for performance reasons.

Loop over the result like this:


var progressCollection = Spark.runtimeCollection("Tribes");
var cursor = progressCollection.find({"": ""});
var doc;
    doc =;


Login to post a comment