Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query projection with MongoDB 10gen driver

Tags:

c#

mongodb

Recently i was playing with mongodb official driver. The problem that i've encountered was how to make query projection. Example if i have a persisted object

class A{
  id
  PropA
  PropB
  List<LargeObjects>
}

How can i only retrieve id, PropA and PropB instead of retrieving the whole object ? How can be done with the mongodb official c# driver ?

like image 465
Marjan Nikolovski Avatar asked Aug 21 '11 20:08

Marjan Nikolovski


1 Answers

Query projection is available through:

MongoCollection<>.Find().SetFields(include/exclude);
like image 163
Marjan Nikolovski Avatar answered Oct 23 '22 04:10

Marjan Nikolovski