Introduction
Boolean and null types help store simple true/false values and empty or missing information in your data.
Jump into concepts and practice - no test required
Boolean and null types help store simple true/false values and empty or missing information in your data.
{ "fieldName": true | false | null }{ "isActive": true }{ "isCompleted": false }{ "middleName": null }This example adds three tasks with different boolean and null values for completion. Then it finds only the tasks marked as completed (true).
db.tasks.insertMany([
{ "task": "Wash dishes", "isCompleted": false },
{ "task": "Do homework", "isCompleted": true },
{ "task": "Read book", "isCompleted": null }
])
// Find tasks that are completed
db.tasks.find({ "isCompleted": true })Boolean values are useful for yes/no or on/off states.
Null is different from false or empty string; it means no value at all.
When querying, use true, false, or null without quotes to match these types.
Boolean stores true or false values.
Null represents missing or unknown data.
Use these types to keep data clear and easy to check.
Boolean type represent in MongoDB?null without quotes.{ "active": true }, { "active": false }, { "active": null }db.collection.find({ "active": { $eq: null } }) return?isActive is false:db.users.find({ isActive: False })verified is either false or null. Which MongoDB query correctly finds these documents?