javascript - MongoDB - dont understand how to loop through collections with a cursor -


advertisers = db.dbname.find( 'my query returns things correctly' ); 

i realize returns cursor list of collections.

but not sure how loop through them , each collection.

i want try this:

advertisers.each(function(err, advertiser) {     console.log(advertiser); }); 

but not work. didn't see searching online how make work simple javascript.

then have code:

var item;  if ( advertisers != null ) {    while(advertisers.hasnext())     {        item = advertisers.next();    } } 

and gives error: syntaxerror: syntax error (shell):1

help appreciated!

thanks!

the quick , dirty way is:

var item; var items = db.test.find(); while(items.hasnext()) {    item = items.next();    /* item */ } 

there more functional:

items.foreach(function(item) {    /* */ }); 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -