Created
June 12, 2011 01:53
-
-
Save gatesvp/1021164 to your computer and use it in GitHub Desktop.
Pull with regex
This file contains 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
MongoDB shell version: 1.8.1 | |
connecting to: test | |
> db.test.insert({ _id:3, "items": [ 'appstore.com', 'engineapp.com', 'asp.ca' ] }) | |
> db.test.find() | |
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca" ] } | |
> db.test.update({}, {$pull : { items: {$regex: 'app' } } }) | |
> db.test.find() | |
{ "_id" : 3, "items" : [ "asp.ca" ] } |
This file contains 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
MongoDB shell version: 1.8.1 | |
connecting to: test | |
> db.test.insert({ _id:3, "items": [ 'appstore.com', 'engineapp.com', 'asp.ca', /app/ ] }) | |
> db.test.find() | |
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca", /app/ ] } | |
> db.test.update({}, {$pull : { items: /app/ } }) | |
> db.test.find() | |
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca" ] } |
tzuryby
commented
Jun 12, 2011
So it worked.
The following entry was updated: "_id": 974978785
Notice how "http://even-home.appspot.com/" is now gone?
Of course, it did not update all documents because you did not set the "multi" flag to true.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment