Insert data into with pymongo and flask Insert data into with pymongo and flask flask flask

Insert data into with pymongo and flask


The method has been deprecated and is changed to .insert_one() in the pymongo 3.x driver, there is also .insert_many() for multiple document creation:

collection.insert_one({'user': username, 'passoword': passowrd})

The .insert() method is now only supported in the 2.x and lower series.


I think, the root cause is in this line:

collection = connection.signup  # collection name.

Contrary to the comment, you're getting a DB named signup. That should rather be:

collection = db.signup


please do make sure that you do this to an existing database,object has been returned successfully.here is my code:

from pymongo import MongoClientclient=MongoClient()db=client.testdbnew={"shopclues":1234,"rating":3}result=db.testdb.insert_one(new)   result.inserted_idObjectId('59e2f0f2031b4b0b27ecfa09')