Is there a way to retrieve data from MongoDB without the _id field?

空扰寡人 提交于 2019-12-10 15:14:31

问题


I am using MongoDB in our project and I'm currently learning how things work.

When inserting records, MongoDB auto generates the ID. When querying data, it always returns _id. This creates a problem when we deserialise the Bson/Json to out objects as our types don't have that field (and we don't really want to put it in).

Does anyone know how to retrieve data without getting _id in the result?


回答1:


Yes, just explicitly omit it:

collection.Find(criteria)
    .SetFields(Fields.Include("oneField", "anotherField").Exclude("_id"))


来源:https://stackoverflow.com/questions/5594436/is-there-a-way-to-retrieve-data-from-mongodb-without-the-id-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!