大师网-带你快速走向大师之路 解决你在学习过程中的疑惑,带你快速进入大师之门。节省时间,提升效率

mongoDB数据库的增删改

https://docs.mongodb.com/manual/reference/method/cursor.forEach/#cursor.forEach

db.getCollection('Cuser').find({"recommend1":{exists:true}}).forEach( function(item){ let recommend1Key = item.recommend1.replace("id_","") let objKey = ObjectId(recommend1Key) db.getCollection('Cuser').update({_id:item._id},{set:{"recommend1Key":objKey}},true)
}
);

// {
// "where": {"status": 1, "username": "17311251006"},
// "include": {
// "relation": "belongsToTeacher",
// "scope": {
// "where": {"status": 1}
// }
// }
// }

// {
// "where": {"status": 1, "username": "17311251006"},
// "include": {
// "relation": "belongsToTeacher"
// }
// }

//{"recommend1":{$exists:true}