简体   繁体   English

PYMongo:查询后,在每条记录中都返回_id,如何排除此记录?

[英]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. 我在使用pymongo对mongodb进行查询时遇到问题。 I do not know how to avoid getting the _id for each record. 我不知道如何避免获取每个记录的_id。

I am doing something like this, 我正在做这样的事情,

result = db.meta.find(filters, [ 'model', 'fields.parent', 'fields.status', 'fields.slug', 'fields.firm', 'fields.properties']) 结果= db.meta.find(过滤器,['模型','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 华金

您可以通过以下方式排除id对象:

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

Does make any sense. 确实有道理。 The object id is core part of each document. 对象ID是每个文档的核心部分。 Convert the BSON/JSON document to a native datastructure (depending on your implementation language) and remove _id on this level. 将BSON / JSON文档转换为本地数据结构(取决于您的实现语言),并在此级别上删除_id。 Apart from that it does not make much sense what you are trying to accomplish. 除此之外,您要完成的目标没有多大意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM