db.employees.find({empno:7369})
{ "_id" : "E1", "empno" : 7369, "ename" : "SMITH", "job" : "CLERK", "hiredate" : "17-12-1980", "sal" : 800, "deptno" : 20 }
db.employees.find({empno:7900}, {ename:1})
{ "_id" : "E2", "ename" : "JAMES" }
db.employees.find({empno:{$gt:7500, $lte:7600}}, {empno:1, ename:1, _id:0})
{ "empno" : 7566, "ename" : "JONES" }
{ "empno" : 7521, "ename" : "WARD" }
db.employees.find($or:[{empno:7782}, {empno:7844}]}, {empno:1, _id:0})
{ "empno" : 7782 }
{ "empno" : 7844 }
db.employees.count()
14
방법1
db.employees.find({empno:{$gt:7900}}).count()
2
방법2
db.employees.count({empno:{$gt:7900}})
2
db.employees.distinct("deptno")
[ 10, 20, 30 ]
db.employees.find({deptno:10}, {ename:1, job:1, _id:0}).sort({ename:-1})
{ "ename" : "PRESIDENT", "job" : "CEO" }
{ "ename" : "CLERK", "job" : "CLERK" }
{ "ename" : "CLARK", "job" : "MANAGER" }
db.employees.aggregate([ $group: {_id:null, total_salary: {$sum: "$sal"}}}])
{ "_id" : null, "total_salary" : 29025 }
db.employees.aggregate([{ $group: {_id: "$deptno", avg_sal: {$avg:"$sal"}}}, {$sort: {_id:1}}])
{ "_id" : 10, "avg_sal" : 2916.6666666666665 }
{ "_id" : 10, "avg_sal" : 2175 }
{ "_id" : 10, "avg_sal" : 1566.6666666666667 }