2

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?

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.