J. Quintas
J. Quintas

Reputation: 2105

PYMongo: Keep returning _id in every record after quering, How can I exclude this record?

I am having problem when I do a query to mongodb using pymongo. I do not know how to avoid getting the _id for each record.

I am doing something like this,

result = db.meta.find(filters, [ 'model', 'fields.parent', 'fields.status', 'fields.slug', 'fields.firm', 'fields.properties'])

I do not want to iterate the cursor elements only to delete a field. Thanks,

Joaquin

Upvotes: 1

Views: 829

Answers (2)

Dick
Dick

Reputation: 1238

You can exclude the id object this way:

db.meta.find({}, {"_id" : 0})

Upvotes: 3

user2665694
user2665694

Reputation:

Does make any sense. The object id is core part of each document. Convert the BSON/JSON document to a native datastructure (depending on your implementation language) and remove _id on this level. Apart from that it does not make much sense what you are trying to accomplish.

Upvotes: 0

Related Questions