Query whether a field exists
Db.student.findOne ({name:{$exists: true}})
Db.student.findOne ({' department.name ': {$exists: true}})
Db.student.findOne ({' department.name ': {$exists: false}})
-------------------------------------------------------------------------------
Determine if the Map object is empty, note that the size can not be judged by $GT, $LT, and the index is used to determine
Db.student.find ({class: {$not: {$size: 0}}}). Limit (2)
Db.student. Find ({' class.0 ': {$exists: 1}})
----------------------------------------------------------------------------------
Determine the size of an array
Db.student. Find ({' class ': {$size: 3}})
Db.student.find ({$where: "This.class.length < 3"})
---------------------------------------------------------------------------------
Formatted output
Select top 1 *from student;
Db.student.findOne ()
Select top 1 *from student where age>15;
Db.student.findOne ({age:{$gt: 15}})
Select Class,department from student where name= ' shell ' and gender=true;
Db.student.findOne ({name:shell,gender:true},{class:1,department:1})
---------------------------------------------------------------------------------
The number of cursor jump queries and qualified returns
Db.department.find (). Skip (10)
Select top Ten *from department;
Db.department.find (). Limit (10)
---------------------------------------------------------------------------------
The value returns the specified field, the first map writes the filter condition, the second map writes the returned field, and the default returns _ID, if it is not necessary to set the _id:0
Db.student.find ({},{name:1,id:1}
Db.student.find ({},{name:1,id:1,_id:0}
--------------------------------------------------------------------------------------
Total queries
Db.student.find (). Count ()
Db.student.find ({age:{$lt:}}). Count ()
-----------------------------------------------------------------------------------
Update and delete a field: Delete the first class and modify the update time to the current time
Db.student.update ({id:10005},{$unset: {' class.0 ': 1}, $set: {Updated:numberlong (New Date (). ValueOf ()/1000)}})
------------------------------------------------------------------------------------
MongoDB Common Commands