UpdateMany gives a error: 'Collection' object is not callable
UpdateMany gives a error: 'Collection' object is not callable
我正在尝试更新文档,我的查询是:
def database_connection():
myclient = MongoClient("mongodb://localhost:27017/")
mydb = myclient["test"]
return mydb
db=database_connection()
collection = db.collection_name
collection.updateMany({"name":"xyz"},{"$set":{'name':'abc'}})
但它给我错误
TypeError: 'Collection' object is not callable. If you meant to call the 'updateMany' method on a 'Collection' object it is failing because no such method exists.
这应该可以解决问题,即 update_many()
而不是 updateMany()
def database_connection():
myclient = MongoClient("mongodb://localhost:27017/")
mydb = myclient["test"]
return mydb
db=database_connection()
collection.update_many({"name":"xyz"},{"$set":{'name':'abc'}})
我正在尝试更新文档,我的查询是:
def database_connection():
myclient = MongoClient("mongodb://localhost:27017/")
mydb = myclient["test"]
return mydb
db=database_connection()
collection = db.collection_name
collection.updateMany({"name":"xyz"},{"$set":{'name':'abc'}})
但它给我错误
TypeError: 'Collection' object is not callable. If you meant to call the 'updateMany' method on a 'Collection' object it is failing because no such method exists.
这应该可以解决问题,即 update_many()
而不是 updateMany()
def database_connection():
myclient = MongoClient("mongodb://localhost:27017/")
mydb = myclient["test"]
return mydb
db=database_connection()
collection.update_many({"name":"xyz"},{"$set":{'name':'abc'}})