首页 > 编程知识 正文

mongodb 批量更新,删除,删除mongodb数据库

时间:2023-05-04 04:47:43 阅读:182055 作者:3373

mongo的一般查询、更新、删除等语句

注:语句中的所有collection都表示mongo表的名称

一般条件操作符: $gt ()、$lt )、$gt )=、$lt )=、$ne )!=)、$eq(=、$add )、$subtract(-)、$multiply(* )和$divide(/) /

咨询:1、基础条件查询

db.collection.find (" type " : " test " );2、区间查询

db.collection.find((type(: ) test )、(addtime ) : ) $LTE:isodate ) 2019-06-111 t 59336059360593600 360000 http://ww

db.collection.find ({“type”:“test”,“ids”: { $ in : [ 1,2,3 ] } );3、数组列表in查询

db.collection.find (“type”:“test”)、sort (“add time”:-1 ) )、skip(0)、limit(2) 2;4、分页排序查询,倒序(-1),正序(1)

db.collection.aggregate ({ $ group : { _ id : ' $ type ',total3360{$sum:'$age'}} );5、分组查询,统计type类型的age总和

db.collection.aggregate ({ $ match : { ' name ' : { $ ne : null } ),{ $ group : { _ id 3360 ' $ type ' 333:

db.collection.aggregate (() $ match : (type ) : ) test )、() remark (: ) $ne: ) )、) $gg )。6、带条件的分组查询,统计name非空,type类型的age总和,这里必须使用$group

db.collection.aggregate ({ $ match : { ' type ' : ' test ' },{$project:{_id:'$id ',sub 3: )

db.collection.aggregate ({ $ match : { ' type ' : ' test ' },{$project:{_id:'$id ',total3360} )

db.collection.update ((_ id (: objectid ) )、) $set: )、true ) : ) test )、false、false 3

db.collection.ensure index ({ type :1 } )删除:7、带条件的分组查询,统计type类型是test,remark不是手动生成任务的重复订单号数量大于1的列表,这里必须使用$group

db.collection.drop ()8、使用aggregate聚合计算查询,查询type类型是test的(age1 / age2)表达式的值,这里必须使用$project

db.collection.remove ({ ' type ' : ' test ' } )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。