db.r0audio.find().forEach(function(item){
db.r0audio.update({"_id":item._id},
{"$set": {"day":item.fileCreateTime.substring(0,8)}},false,true)
});
# function语法为js,实现更新一个字段的值为另外一个字段的值
db.r0audio.aggregate([
{ $match: {"fileInfoPushTime":{$gte:"202305190000"}}},
{$group:{"_id":{$substr:['$fileInfoPushTime',0,8]}, count:{$sum:1}}}
]);
# mongo截取字符串后group by count
db.r0audio.aggregate(
{"$match":{"pid":{"$in":["914013694","914013669","914013668","914013628","914013588"]},"fileInfoPushTime":{$gte:"20230101000000"}}},
{
"$group": {
"_id": "$pid",
"count": {
"$sum": "$duration"
}
}
}
)
# 分组查询聚合统计