sophros
sophros

Reputation: 16700

MongoDB - querying GridFS by metadata does not return any results

I am trying to query MongoDB database for a file stored in GridFS using metadata in the following way:

db['fs'].files.find({'metadata': {'a_field': 'a_value'}})

And it does not return any results whereas I can see the file with such a field value exists when I run e.g.:

db['fs'].files.find()

What is wrong about my query?

Upvotes: 2

Views: 184

Answers (1)

sophros
sophros

Reputation: 16700

It turns out the problem is solved by changing the nesting of JSON query document from:

{'metadata': {'a_field': 'a_value'}}

to:

{'metadata.a_field': 'a_value'}

It is still a mystery to me why the two queries are not equivalent, though.

Upvotes: 2

Related Questions