mongodb FindAndModify - 更新数据 [英] mongodb FindAndModify - update data

查看:54
本文介绍了mongodb FindAndModify - 更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 MongoDB 集合中有这个了.

I have this already in the MongoDB collections.

{ "_id" : ObjectId("4e677efce88c7f0718000000"), "ptbn" : "indl000000001", "tbucode" : "5649", "district" : "west", "dcode" : "110048":超级诊所",州":德里"}

{ "_id" : ObjectId("4e677efce88c7f0718000000"), "ptbn" : "indl000000001", "tbucode" : "5649", "district" : "west", "dcode" : "110048", "tbu" : "super clinic", "state" : "delhi" }

我无法理解如何使用来自 MongoDb 的 FindAndModify

I am unable to understand how to work with FindAndModify from MongoDb

我正在开发 MongoDb 1.8

I am working on MongoDb 1.8

我只想将州"从德里修改为果阿,将区"从西修改为北.

I just want to modify the 'state' from delhi to goa, and 'district' from west to north.

如何在 Python-2.6 中修改除 'ptbn' 之外的所有条目

How do I modify all entries EXCEPT 'ptbn' in Python-2.6

这是我迄今为止尝试过的:

This is what I've tried so far:

     connection = Connection('localhost', 27017)
     db = connection.health
     tc = db.tc_basic

     basic = {'state' : state, 
              'district' : district,
              'Dcode' : Dcode, 
              'tbu' : tbu,
              'tbucode' : tbucode,
              'ptbn' : ptbn
              }

     tc.save(basic)

推荐答案

您实际上不需要 findAndModify 来解决这个问题.一个简单的 update() 就可以解决问题.

You don't actually need findAndModify for this. A simple update() will do the trick.

db.tc_basic.update({'_id':ObjectId("...")}, {'$set': {'state': 'goa', 'district': 'north'}})

有关您可以使用 update() 做什么的更多详细信息,请参阅:http://www.mongodb.org/display/DOCS/Updating

For more details on what you can do with update() see: http://www.mongodb.org/display/DOCS/Updating

这篇关于mongodb FindAndModify - 更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆