问题
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