0

All my documents have a structure like this:

{
   operational: {availableFleet: [Objectid('5bad3f452641a1186d21b5f8'), ...]}
}

So every document has an operational key with many other keys inside, one of them being availableFleet which is an Array of multiple ObjectIds

I want to retrieve all documents that contain one specific ObjectId inside the availableFleet Array.

Here's my query:

{operational: {availableFleet: {$in: [ObjectId('5bad3f452641a1186d21b5f8')]}}}

However, it's returning nothing.

I'm using the MongoDB Compass GUI.

1 Answer 1

1

Should be:

{'operational.availableFleet': ObjectId('5bad3f452641a1186d21b5f8')}

No need for $in as this is for the case of multiple options for the ObjectId('5bad3f452641a1186d21b5f8').

And nested objects are marked with a .

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.