Skip to main content

3 posts tagged with "database"

View All Tags

MongoDB中使用$rename指令修改字段名

· One min read

如下所示:把 collection Policy中的 Type 为 1 的所有 document 的 UserID 字段修改为 UserName, multi 为 true 表明修改所有记录,upsert 为 false 表明记录不存在则不创建:

db.getCollection('Policy').update({"Type":1},{$rename:{'UserID': 'UserName'}},{"multi" : true, "upsert" : false})

参考:https://docs.mongodb.com/manual/reference/operator/update/rename/

ClustrMaps