Created
April 29, 2017 09:08
-
-
Save SarasArya/ba97d1364a28b52ce5163857861e2b6c to your computer and use it in GitHub Desktop.
mongodb commands I find useful, especially when dealing with embedded documents.
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
//To remove a field from each document. Whenever I introduce a field by mistake | |
db.example.update({}, {$unset: {words:1}} , {multi: true}); | |
//To search in array of objects in mongodb | |
db.collection.find( { field1: { $elemMatch: { one: 1 } } } ); | |
//To update array of objects in mongodb console | |
db.roles.update({"userId" : ObjectId("58a191b8d02dde3638a5a4ee"), "children.requestStatus" : 'Rejected'},{$set : {"children.$.requestStatus" : "Authorized"}}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment