--查询 ---等价 select * from table
db.ConnectorInfo.find()
---带参数查询 等价 select * from table where id='ebed0c245c064945acbbb2b36cb2e2c2'
db.ConnectorInfo.find({"_id":"ebed0c245c064945acbbb2b36cb2e2c2"})
---带参数查询 等价 select * from table where id='ebed0c245c064945acbbb2b36cb2e2c2' and method='getUnitPersonnel'
db.ConnectorInfo.find({"_id":"ebed0c245c064945acbbb2b36cb2e2c2","method":"getUnitPersonnel"})
---带参数查询 等价 select id,method from table
db.ConnectorInfo.find({},{"_id":1,"method":1})
---带参数查询 等价 select imethod from table
db.ConnectorInfo.find({},{"_id":0,"method":1})
//$lt(<) $lte(<=) $gt(>) $gte(>=) $ne(<>不等于) $in(in) $nin(not in) $or(or) $mod(取模运算) $not(在指定的表达式并查询到不匹配表达式)
---带参数查询 等价 select * from table where time >= '2022-08-01' and time <= '2022-08-10'
db.ConnectorInfo.find({"time":{"$gte":"2022-08-01","$lte","2022-08-10"}})
aggregate分组 等价于 select by_user, count(*) from mycol group by by_user
-----分组count
db.ConnectorInfo.aggregate([{$group : { _id:"$host", num_tutorial:{$sum : 1}}}])
-----修改指定文档
db.getCollection("ConnectorInfo").update({'title':'MongoDB 教程'},{$set:{'title':'MongoDB'}})
-----删除指定文档
db.ConnectorInfo.remove({'_id':'7f9e2cf2b170406a9fb5f8262f8b2f09'})
-----添加文档记录
db.col.insert({title: 'MongoDB 教程',
description: 'MongoDB 是一个 Nosql 数据库',
by: '菜鸟教程',
url: 'http://www.runoob.com',
tags: ['mongodb'],
likes: 100
})
支持正则表达式查询
---对数组查询
$all(对数组查询)
$slice : {"$slice":10} 只返回数组前10条 {"$slice":[23,10]} 返回中间10条 {"$slice":-10} 返回最后10条
--------java代码示例部分
db.COLLECTION_NAME.find({"moduleName":"接口名称"}).limit(NUMBER).skip(NUMBER);
等价于下面代码:
Query query = new Query();
if (StringUtils.isNotEmpty(logStatisticsBo.getBusinessType())) {
query.addCriteria(Criteria.where("moduleName").is(logStatisticsBo.getBusinessType()));
}
long count = mongoTemplate.count(query, ConnectorInfo.class);
query.skip(logStatisticsBo.getPageNum());
query.limit(logStatisticsBo.getPageSize());
List<LogStatisticsInfo> connectorInfoList = mongoTemplate.find(query, LogStatisticsInfo.class,"ConnectorInfo");