Sign In Register

How can we help you today?

Start a new topic
Answered

How to iterate over runtime collections?

I tried both:

 

var esc_regCollection = Spark.runtimeCollection("ESCReg");
    var playerIDs = [];
    
    for( var it = 0; it < esc_regCollection.count(); ++it ){
        // [] invalid
        var regPlayer = esc_regCollection[it];
        
        playerIDs.push(regPlayer._id);
    }
    // hasNext invalid
    while( esc_regCollection.hasNext()){
        
        var regPlayer = esc_regCollection.next();
        
        playerIDs.push(regPlayer._id);
    }

 


Best Answer

Hi Giuliano


You just need to add a find query to get a SparkMongoCursor


This code will work 

var esc_regCollection = Spark.runtimeCollection("ESCReg").find();

    var playerIDs = [];

   

    while( esc_regCollection.hasNext()){

        

        var regPlayer = esc_regCollection.next();

        

        playerIDs.push(regPlayer._id);

    } 


Regards

Katie

1 Comment

Answer

Hi Giuliano


You just need to add a find query to get a SparkMongoCursor


This code will work 

var esc_regCollection = Spark.runtimeCollection("ESCReg").find();

    var playerIDs = [];

   

    while( esc_regCollection.hasNext()){

        

        var regPlayer = esc_regCollection.next();

        

        playerIDs.push(regPlayer._id);

    } 


Regards

Katie

Login to post a comment