Removing _id element from Pymongo results

后端 未结 3 1947
挽巷
挽巷 2021-02-01 02:44

I\'m attempting to create a web service using MongoDB and Flask (using the pymongo driver). A query to the database returns documents with the \"_id\" field included, of course

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 03:45

    To exclude the _id field in a find query in pymongo, you can use:

    db.collection.find({}, {'_id': False})
    

    The documentation is somewhat missleading on this as it says the _id field is always included. But you can exclude it like shown above.

提交回复
热议问题