如何在mongodb中上调?

时间:2018-10-07 01:55:47

标签: python pymongo

我正在尝试在mongodb中进行如下更新,并遇到以下错误?我查看了其他帖子pymongo typeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument,但我找不到任何具体的东西?有关如何解决它的任何指南?

from pymongo import MongoClient
import os,pymongo,re
dbuser = os.environ.get('user', 'techauto1')
dbpass = os.environ.get('pwd', 'techpass')
uri = 'mongodb://{dbuser}:{dbpass}@machine.company.com:27017/techautomation'.format(**locals())
client = MongoClient(uri)
db = client.techautomation
data = {}
data["chip"] = '1234'
data["firmware_version"] = '0.10.560.0.5.1.22'
data["train"] = 'abcd'
try:
    db.latest_fw_released.update(data,True)
    logger.info('wrote')
    logger.info('Updated %s into DB...'%data)
except pymongo.errors.AutoReconnect, e:
    logger.info( 'Warning:%s'%e)

错误:-

    db.latest_fw_released.update(data,True)
  File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 2951, in update
    common.validate_is_mapping("document", document)
  File "/Library/Python/2.7/site-packages/pymongo/common.py", line 425, in validate_is_mapping
    "collections.Mapping" % (option,))
TypeError: document must be an instance of dict, bson.son.SON, or other type that inherits from collections.Mapping

0 个答案:

没有答案