
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to insert a boolean field in MongoDB?
Since boolean has two values: true and false, therefore, use true or false keyword in MongoDB. Let us create a collection with documents −
> db.demo215.insertOne({"EmployeeDetails":[{EmployeeName:"David","isMarried":false,"Salary":56000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e344003d395bdc2134708") } > db.demo215.insertOne({"EmployeeDetails":[{EmployeeName:"Bob","isMarried":true,"Salary":60000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e344d03d395bdc2134709") } > db.demo215.insertOne({"EmployeeDetails":[{EmployeeName:"Chris","isMarried":false,"Salary":78000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e345a03d395bdc213470a") } > db.demo215.insertOne({"EmployeeDetails":[{EmployeeName:"Mike","isMarried":true,"Salary":17000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e346f03d395bdc213470b") }
Display all documents from a collection with the help of find() method −
> db.demo215.find();
This will produce the following output −
{ "_id" : ObjectId("5e3e344003d395bdc2134708"), "EmployeeDetails" : [ { "EmployeeName" : "David", "isMarried" : false, "Salary" : 56000 } ] } { "_id" : ObjectId("5e3e344d03d395bdc2134709"), "EmployeeDetails" : [ { "EmployeeName" : "Bob", "isMarried" : true, "Salary" : 60000 } ] } { "_id" : ObjectId("5e3e345a03d395bdc213470a"), "EmployeeDetails" : [ { "EmployeeName" : "Chris", "isMarried" : false, "Salary" : 78000 } ] } { "_id" : ObjectId("5e3e346f03d395bdc213470b"), "EmployeeDetails" : [ { "EmployeeName" : "Mike", "isMarried" : true, "Salary" : 17000 } ] }
- Related Articles
- MongoDB Query for boolean field as “not true”
- How to insert a Python object in Mongodb?
- How can I add a Boolean field to MySQL?
- How to increment a field in MongoDB?
- How to insert Date in MongoDB?
- How to insert a document with date in MongoDB?
- How to select a single field in MongoDB?
- How to make a unique field in MongoDB?
- How to insert LONG numbers in MongoDB?
- Insert MongoDB document field only when it's missing?
- How to determine whether a field exists in MongoDB?
- How to check empty field in a MongoDB collection?
- How to compare field values in MongoDB?
- How to improve querying field in MongoDB?
- How to update _id field in MongoDB?

Advertisements