0

I am trying to add a new record into mongodb using fastapi endpoint the data is inserting successfully into the db but also recieving the follwoing error from endpoint can anything tells that whats the actuall problem.

ValueError: [TypeError("'InsertOneResult' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • 2
    Welcome to stack overflow. For us to help you, we need to see some code. Please create a [mcve] that reproduces the error and [edit] your question to include it. – Code-Apprentice Sep 26 '22 at 18:27

1 Answers1

0

The problem appears to be in the return value. The return value of the insert method is the inserted _id(s) and acknowledged. The return type is <class 'pymongo.results.InsertOneResult'> . I'm not very good at coding, so I'm not sure why it doesn't return, but it does. Try getting the ids back

reference:

https://motor.readthedocs.io/en/stable/api-tornado/motor_collection.html?highlight=insert#motor.motor_tornado.MotorCollection.insert_one

https://pymongo.readthedocs.io/en/4.3.3/api/pymongo/results.html

How to get the object id in PyMongo after an insert?

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34336818) – Alez May 08 '23 at 11:05