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
Post a Comment