Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pymongo return data without _id

As the title says, how can I find() in my mongo all the data but without the _id index in the list.

Of course I can drop it later like:

for i in data:
   del i['_id']

But is there a more elegant solution without needing that loop?

like image 641
Diolor Avatar asked Jun 03 '26 14:06

Diolor


1 Answers

If I understand your question correctly, I think you're looking for projections:

http://docs.mongodb.org/manual/reference/method/db.collection.find/#projections

Something like this should do it:

db.test.find(query,{"_id":0})
like image 182
Chris Chang Avatar answered Jun 06 '26 02:06

Chris Chang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!