查询
- 判断集合是否为空:
"rowData":{}
- 数组修改:
"$set":{"rowDatas.0.texts":["755073291"]}
- 判断是否串长度
"areaId": {"$regex": /^.{0,12}$/} //长度小于12
"areaId": {"$regex": /^.{12,}$/} //长度大于12
db.getCollection('stats_working_gathered_respondent_task').find({"areaId":"$areaId"}).forEach(function(task){
db.getCollection('stats_working_gathered_respondent_task').update({"_id":task._id},{"$set":{"areaId":task.areaId+"000000"}})
})
- 比较运算符:大于
$gt | $gte
,小于$lt | $lte
聚合
//sql
"areaId": {"$not": /^[0-9]+$/}
//java
not().regex("^[0-9]+$")
//mongo
{"$sort":{"periodId":-1}}
//java
Aggregation.sort(new Sort(Sort.Direction.DESC, "periodId"))
配置索引
- 数据库
name | idx_report_period_respondent
keys |
{
"reportCode" : 1,
"respondentId" : 1,
"periodId" : -1
}
- 代码
//加在实体上
@CompoundIndexes({
@CompoundIndex(name = "idx_report_period_respondent", def = "{'reportCode': 1,'respondentId': 1,'periodId': -1}")
})
注
- 使用客户端插入多条数据时,数据之间不需要逗号分隔。
网友评论