Hustler
Hustler

Reputation: 15

UpdateMany gives a error: 'Collection' object is not callable

I am trying to update the document my query for it is:

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'}})

but it is giving me error

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.

Upvotes: 0

Views: 4896

Answers (1)

Nam G VU
Nam G VU

Reputation: 35434

This should do the trick for you i.e. update_many() instead of 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'}})

Upvotes: 3

Related Questions