Facundo Chambo
Facundo Chambo

Reputation: 3398

Querying mongodb with $in not working

Why is this query not working?

>db.fs.files.find()
{ "_id" : ObjectId("550a34129c44a4fa03fb78ea"), "filename" : "mJnB2DhK.png", "contentType" : "binary/octet-stream", "length" : 28297, "chunkSize" : 261120, "uploadDate" : ISODate("2015-03-19T02:27:30.757Z"), "aliases" : null, "metadata" : { "id" : "mJnB2DhK" }, "md5" : "85944f92db940c6590fc8059db91ea16" }
{ "_id" : ObjectId("550a34ed48f6205504285a3b"), "filename" : "mkPQ6wnY.png", "contentType" : "binary/octet-stream", "length" : 28297, "chunkSize" : 261120, "uploadDate" : ISODate("2015-03-19T02:31:10.069Z"), "aliases" : null, "metadata" : { "id" : "mkPQ6wnY" }, "md5" : "85944f92db940c6590fc8059db91ea16" }
>db.fs.files.find({"metadata": {"id": { $in: ["mkPQ6wnY","mJnB2DhK"]}}})
>

I can't find the difference on this query against the one in the docs, except that my $in comparison is in a second level, but I don't think that would be a problem for MongoDB.

I guess is a very silly mistake, but I can't see it.

Upvotes: 1

Views: 1953

Answers (1)

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

Try

db.fs.files.find({"metadata.id": { $in: ["mkPQ6wnY","mJnB2DhK"]}})

Upvotes: 3

Related Questions