Reputation: 21
I have a collection with a bunch of documents. I want to find within a large string object (an unformatted key/value) and extract data from it.
Is it possible to use something like this:
db.apps.find({config: '/\n\n(.*) = (.*)\n\n?/'})
to extract these pair of values?
I'm trying to do this with php, but is getting really slow.
How can I find a clean way to solve it?
Upvotes: 2
Views: 1201
Reputation: 3266
If I'm understanding your question correctly, unfortunately mongo will probably not be able to perform this query quickly. The "find" command will only find documents where the "config" value matches that regex, but that query could be slow. Even if you have an index on the "config" field, the index can only be used to match a fixed prefix of a regexp (see here: http://www.mongodb.org/display/DOCS/Advanced+Queries).
As for extracting data from the string, you'll have to do that in your application code after you make the query.
Is it possible to reformat your data so that the key-value information is stored as key-values in the document itself, rather than embedded in a string?
Upvotes: 2