anthonypliu
anthonypliu

Reputation: 12437

How to query indexes in mongodb using the C# driver

I have the following data structure:

{
   eventname: "blah",
   invitees: [
     {
        inviteid: 1,
        userid: 34234
     },
     {
        inviteid: 2,
        userid: 5232
     }]
}

I am going to use ensureIndex on my invitees column so i do not have to search through every document to find specific userids in the invitees column. Its basically searching for events that a specific userid was invited to. I was suggested to use this db.events.find({"invitees.userid" : 34234}) to query it, but how do i do this in c# with then 10gen driver. the .find method only accepts a Mongo Query object.

Upvotes: 1

Views: 2777

Answers (1)

Wayne Tanner
Wayne Tanner

Reputation: 1356

The way that I'm doing it is:

var collection = db.GetCollection<MyType>("collectionName");
var query = Query.EQ("fieldname", valueToQuery);
var results = collection.Find(query);

Upvotes: 1

Related Questions