def update_data(self):
for i in self.collection.find():
self.collection.update( {'_id' : i['_id']},{'$set': {'new':123}})
遍历所有数据,取出id,给每条数据设置新值
其他方法:
db.getCollection(‘reports_stock’).updateMany({},{KaTeX parse error: Expected 'EOF', got '}' at position 13: set:{sync:0}}̲) db.getCollect…set:{used:“0”}})
查询某个字段是否存在
db.course.find( { “lectures.lectures_count”: { $exists: true } } )
删除
db.getCollection(‘ZhiHu’).remove({‘answer_list’:[]})