How would I translate this mongo query to a Query.EQ statement in C#?
db.users.find({name: 'Bob'}, {'_id': 1});
In other words, I don’t want everything returned to C# — Just the one element I need, the _id. As always, the Mongo C# Driver tutorial is not helpful.
Update: With new driver version (1.6+) you can avoid fields names hard-coding by using linq instead:
You can do it via
SetFieldsmethod of mongodb cursor:By default
SetFieldsincludes specified fields. If you need exclude certain fields you can use:Or you can use them together: