boolean에는 true와 false의 두 가지 값이 있으므로 MongoDB에서는 true 또는 false 키워드를 사용합니다. 문서로 컬렉션을 만들자 −
> 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") }
find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo215.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_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 } ] }