0

I have a document like this:

{
    "_id" : "4mDYgt6gID",
    ...
    "MultipleChoiceQuestions" : [ 
        {
            ...
            "LeadInFile" : null,
            ...
        },
        {
            ...
            "LeadInFile" : 'some string',
            ...
        }
    ],
    ...
}

How do I query for any documents that have a non-null value in LeadInFile?

I'm trying different things, currently something like this db.getCollection('QuizTime:Quizzes').find({"MultipleChoiceQuestions": [{ "LeadInFile": { $ne: null}}]});

Is returning 0 records.

1 Answer 1

1

The current form of the query is saying:

Find documents where MultipleChoiceQuestions is [{ "LeadInFile": { $ne: null}}]

Try using dot notation; this is used to access elements of an array or fields in an embedded document. For example:

db.getCollection('QuizTime:Quizzes').find({
  "MultipleChoiceQuestions.LeadinFile" : { "$ne" : null }
})
Sign up to request clarification or add additional context in comments.

1 Comment

Upvote for also explaining what my attempt was doing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.