I'm using C# mongo driver and I have users collection like below,
public class User
{
public string Name { get; set; }
public DateField Date { get; set; }
/*
* Some more properties
*/
public List<string> Slugs { get; set; } //I just need to return this property
}
I'm writing a query in which it just returns me the slugs property. To do this i'm trying to use SetFields(...)
method from the mongo driver. SetFields returns the cursor of the User
type i'm expecting something to be of my Slugs
property type so that I don't return whole set of properties when i just need one. Is it possible ?
Yes and no. You can use the aggregation framework's projection operator $project
to change the structure of the data, but I wouldn't do that for two reasons:
After all, omitting a few fields is a micro-optimization already (setting index covered queries aside), but on the client-side the cost of empty fields should be next to none.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.