2

How can i do this from c# mongoDb drivers.

sql query :SELECT a,b FROM users

mondb javascript query : db.users.find({}, {a:1,b:1})

i3arnon
  • 113,022
  • 33
  • 324
  • 344
gsagrawal
  • 2,900
  • 4
  • 27
  • 27
  • possible duplicate of [How to retrieve a subset of fields using the C# MongoDB driver?](http://stackoverflow.com/questions/6540160/how-to-retrieve-a-subset-of-fields-using-the-c-sharp-mongodb-driver) – mookid8000 Feb 02 '12 at 13:25

1 Answers1

3

How about this:

 var database = MongoDatabase.Create(connectionString);
 var userCollection = database.GetCollection<Exercise>("users");
 var users = userCollection.Find().SetFields("a", "b");

If I understand your question correctly .SetFields does what you want.

Christian Horsdal
  • 4,914
  • 23
  • 24