Skip to content

Instantly share code, notes, and snippets.

@develop7
Created December 29, 2011 22:56
Show Gist options
  • Save develop7/1536576 to your computer and use it in GitHub Desktop.
Save develop7/1536576 to your computer and use it in GitHub Desktop.
Thing I've learned today
// way to shoot your own leg
var q = db.some_collection.find({something: "awful"});
q.forEach(function(o) {print(o.foo)}) //this will print something affects map() too
q.forEach(function(o) {print(o.bar)}) //will print nothing
/* because */ q.hasNext() // == false after first call
//right way is to reassign q or don't use it at all
db.some_collection.find({something: "awful"}).forEach(function(o) {print(o.foo)}) //will work
db.some_collection.find({something: "awful"}).forEach(function(o) {print(o.bar)}) //will print stuff too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment