MongoDB 笔记

1.批量更新或添加字段值

db.getCollection('MainDocument').find({}).forEach(
function(x){
db.getCollection('MainDocument').update({"_id":x._id},{$set:{"subcategoryorder":NumberInt(x.StrSubCategory.split(' ')[0].split('.')[1])}})
}
)

split:MongoDB拆分字符串函数;NumberInt:MongoDB字符串转换成数字类型;"$set":字段存在则更新字段值,字段不存在则插入此字段和值

原文地址:https://www.cnblogs.com/dxmdiy/p/MongoDB.html