Akshat Akshat - 5 months ago 62
Vb.net Question

MongoDB C# Driver multiple field query

Using the MongoDB C# driver How can I include more than one field in the query (Im using vb.net)

I know how to do (for

name1=value1
)

Dim qry = Query.EQ("name1","value1")


How can I modify this query so I can make it find all documents where
name1=value1
and
name2=value2
?

( Similar to )

db.collection.find({"name1":"value1","name2":"value2"})

Answer

Use And method - C# example from tutorial:

MongoCollection<BsonDocument> books;
var query = Query.And(
    Query.EQ("author", "Kurt Vonnegut"),
    Query.EQ("title", "Cats Craddle")
);