0

How to check Collections.insert() is Successfully Inserted or not with pymongo?. For example :

db.results.insert_one({'a':aaa})

How to know the above insert query is successfully inserted or not?

AVIVA
  • 23
  • 5
  • on which side? on yours or on `MongoDb`'s? – Azat Ibrakov Jun 22 '17 at 12:47
  • Documentation of [`insert_one()`](http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert_one) shows you it returns an [`InsertOneResult`](http://api.mongodb.com/python/current/api/pymongo/results.html#pymongo.results.InsertOneResult) – Neil Lunn Jun 22 '17 at 12:47
  • Thanks, but how can I catch an error of insertion? – AVIVA Jun 22 '17 at 13:54
  • 1
    > insertStatus = self.db['Record'].insert_one({'name' : 'bar' }) > print(insertStatus.acknowledged) – Sadia Jul 19 '21 at 13:17

0 Answers0