我使用了Pymongo upsert = true,但是无法插入包含“时间”数据的新记录,请帮我解决。
def mongo_upsert(coll_name, id, data):
try:
mdb = MongoClient('mongodb://localhost:27017')
mainMdb = mdb['main']
coll = mainMdb[coll_name]
# data object
# data = {
# '_id': '989',
# 'charge_booking_type': 'time'
# }
# force set again
data[ 'charge_booking_type'] = str('time')
coll.update({'_id': id}, {'$set': data}, upsert=True)
except Exception as ex:
print 'mongo upsert error', ex
获取错误:
/usr/local/lib/python2.7/site-packages/pymongo/collection.py:479:RuntimeWarning:无法编码-重新加载python模块并重试。如果您看到此消息却没有收到InvalidDocument异常,请参阅http://api.mongodb.org/python/current/faq.html#does-pymongo-work-with-mod-wsgi check_keys,self .__ uuid_subtype),安全) mongo upsert错误无法编码对象: