Section 7: Read Operations – A Closer Look

Query Selectors & projection operators https://docs.mongodb.com/manual/reference/operator/query/ db.tvshows.find({$and: [{“schedule.time”: “21:00”}, {“network.country.code”: “US”}]}).pretty()  db.tvshows.find({“rating.average”: {$gt: 9.2}}).pretty()  db.tvshows.find({“weight”: {$in: [95, 100]}}).pretty() Toán tử $or kiểm tra nếu thỏa mãn một trong 2 thì đều đúng db.tvshows.find({$or: [{“rating.average”: {$lt: 5}}, {“rating.average”: {$gt: 9}}]}).count() 9 db.tvshows.find({“rating.average”: {$lt: 5}}).count() 2 db.tvshows.find({“rating.average”: {$gt: 9}}).count() 7 Toán tử $nor trả về documents nếu […]

Section 6: Diving Into Create Operations

Understanding “insert()” Methods Thêm dữ liệu mới vào collection có cách thông qua phương thức insertOne(), insertMany(), insert()  db.persons.insertOne({name:”Max”, age:30, hobbies:[“Sports”, “Cooking”]}) Thêm mới nhiều document 1 lúc vào 1 collection.  db.persons.insertMany([{name: “Tam”, age: 31, hobbies: [“nauan”, “dicho”]}, {name:”Quynh”, age: 19, hobbies:[“chupanh”,”hochanh”,]}]) Thêm mới dùng insert() sẽ vừa insert được 1 document hoặc nhiều document. […]