Reputation: 1158
Assuming a collection like this:
People
{
"name": "John Doe",
"email": "John Doe <[email protected]>",
"stuff": "foo"
"morestuff": "bar"
},
{
"name": "Homer Simpson",
"email": "Homer Simpson <[email protected]>",
"stuff": "bar"
"morestuff": "foo"
},
{
"name": "Bart Simpson",
"email": "Bart Simpson <[email protected]>",
"stuff" : "foo"
"morestuff": "foo"
"evenmore": ["bar", "foo", "baz"]
}
What might be the best way to find all occurrences of the string 'foo' (exactly, no substring), where ever it might occur? What I'd like to accomplish is to update all occurrences of the string 'foo' to some other string, or delete it from a document in the collection.
I know this might look like a bad database design, I just want to make clear what I'd like to do :)
Upvotes: 0
Views: 914
Reputation: 262504
There is no query that will do that.
For the general case, you have to iterate over all documents, and look at all properties.
If you can limit the possible property keys, you can construct a query like
name = 'foo' or email = 'foo' or stuff ='foo'
or morestuff = 'foo' or evenmore = 'foo'
If the latter is possible, you can also split it into separate queries for every field, which makes sense because you can then also turn them into atomic update queries to change the value to the new one.
Upvotes: 1