tags:

views:

26

answers:

1

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), whereever it might occur? What I'd like to accomplish is to update all occurences 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 :)

+1  A: 

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.

Thilo
Thanks for the answer. I felt like that there is no simple solution, just like it is the case in RDBMS. Maybe one can do something like that using map/reduce?
xl-t