Skip to content

Instantly share code, notes, and snippets.

@mumrah
Created July 15, 2010 15:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumrah/477121 to your computer and use it in GitHub Desktop.
Save mumrah/477121 to your computer and use it in GitHub Desktop.
ObjectId dereferencing in JavaScript for MongoDB
var _deref = function (doc, field, col) {
var oid = ObjectId(doc[field]);
delete doc[field];
doc[field] = db[col].findOne({_id:oid});
return doc;
}
var deref = function(field, collection){
// C-C-C-Closure!!
return function(doc){
return _deref(doc, field, collection);
}
}
@mumrah
Copy link
Author

mumrah commented Jul 15, 2010

For dereferencing ObjectIds in mongoDB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment