Created
July 15, 2010 15:37
-
-
Save mumrah/477121 to your computer and use it in GitHub Desktop.
ObjectId dereferencing in JavaScript for MongoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For dereferencing ObjectIds in mongoDB