1

Theres something here I can't quite figure out.

When I attempt to query an object with several fields I yield no results. The object structure looks like this:

{ 
    "_id" : ObjectId("4d8b55f017a7303b0b000000"), 
    "title" : "Apollo", 
    "body" : "A spaceflight mission to the moon", 
    "tags" : [ [ "moon", "space", "nasa", "mission" ] ] 
}

This is my query:

db.test.find({ tags: { $all: ['moon', 'mission'] } })   

However I do get result by creating a new object with a single field:

{ 
    "_id" : ObjectId("4d8b9e5935037b3c8228709c"), 
    "tags" : [ "apple", "banana", "pear" ] 
}

... with the same query as the one above.

['tags'] isn't nested inside any other array, so why does it not return my search queries? Please enlighten me.

Sincerely, Why

2 Answers 2

3

Why are you using a nested array

"tags" : [ [ "moon", "space", "nasa", "mission" ] ]

here?

This does not make any sense.

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

Comments

0
db.test.find({ tags: { $all: [ ['moon', 'mission'] ] } })  

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.