0

I have a mongodb collection like


{
    template_id: { type: String, required: true },
    owner: {
        user_id: { type: String, required: true }
    },
    assignee: {
        user_id: { type: String, required: false }
    }
    //...other fields
}

There is a compound index (non-sparse & non-unique) for this document,

{ template_id: 1, owner: 1, assignee: 1 }

In this document the assignee may have value or may be null. However, the query pattern for fetching records having null is important.

Are records having null values indexed so that I can use for querying based in them?

2
  • "In this document the owner and assignee may have value or may be null" - Then your schema is incorrect since required means it cannot be either missing or null. There are also specific differences between "missing" and null for both queries and indexes. Commented Apr 8, 2019 at 11:20
  • I have updated the schema. The business scenario is field "assignee" may or may not be available during the save operation. If its not available, then the field "assignee" will be saved with null value. The query for all unassigned records then would be : "fetch all records where assignee is null". In this case does the compound index work or will it go for a full scan ? Commented Apr 8, 2019 at 16:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.