1

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.

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Once you create the index on the column you can just query normally and it does everything for you?
Yes. You can use the .explain() command to verify the index, if any, that is used in a query
That's correct. You don't have to do anything to cause it to use the index. If you don't see the benefit you're expecting from the index, using the explain command as sambomartin mentioned above will show the index being used if one is used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.