/*select count(*) from employees*/
>db.employees.aggregate([{$group:{_id:null, count:{$sum:1}}}])

/*select sum(sal) from employees*/
>db.employees.aggregate([{$group:{_id:"$deptno",total:{$sum:"$sal"}}}])

/*select deptno,sum(sal) from employees where sal=3000 group by deptno*/
>db.employees.aggregate([{$match:{sal:3000}}, {$group:{_id:"deptno", total:{$sum:"$sal"}}}])

/*deptno가 10인 데이터를 조회*/
>db.employees.find({deptno:{$all:[10]}},{_id:0, empno:1,ename:1,sal:1})

/*deptno가 10이고 deptno가 30인 데이터를 조회*/
>db.employees.find({deptno:{$all:[10,30]}},{_id:0, empno:1,ename:1,sal:1})

>db.employees.find({$and:[{deptno:10},{deptno:30}]},{_id:0, empno:1,ename:1,sal:1})

/*deptno가 10이거나 deptno가 30인 데이터를 조회*/
>db.employees.find({deptno:{$in:[10,30]}},{_id:0, empno:1,ename:1,sal:1})

>db.employees.find({$or:[{deptno:30},{deptno:10}]},{_id:0, empno:1,ename:1,sal:1})

/*comm field가 존재하는 데이터만 조회하라*/
db.employees.find({comm:{$exists:true}},{_id:0,empno:1,ename:1})

'mongoDB' 카테고리의 다른 글

mongoDB select문  (0) 2013.03.11
mongoDB 명령어  (1) 2013.03.08
by pacino.kang 2013. 3. 13. 13:31