-
-
Save timelf123/4cf01f1de7fa5349a71f15db18c0f5e0 to your computer and use it in GitHub Desktop.
Add findOneById to MongoShell's DB collection
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
| /**************************************************************************** | |
| * Add this snippet to ~/.mongorc in order to load it to any shell initiated | |
| * Usage: | |
| * db.myCollection.findOneById("5149cdbb62d5cbb22c000024") | |
| * db.myCollection.findOneById("5149cdbb62d5cbb22c000024",{"field":1}) | |
| *****************************************************************************/ | |
| DBCollection.prototype.findOneById = function(objId ,fields, options ){ | |
| return this.findOne({"_id":ObjectId(objId)}, fields, options); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment