Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"})
like image 208
Tarang Avatar asked Sep 23 '12 11:09

Tarang


1 Answers

I wanted to search a text in different fields and Full Text Search doesn't work for me even after wasting so much time. so I tried this.

var filter = Builders<Book>.Filter.Or(
    Builders<Book>.Filter.Where(p=>p.Title.ToLower().Contains(queryText.ToLower())),
    Builders<Book>.Filter.Where(p => p.Publisher.ToLower().Contains(queryText.ToLower())),
    Builders<Book>.Filter.Where(p => p.Description.ToLower().Contains(queryText.ToLower()))
            );
List<Book> books = Collection.Find(filter).ToList();
like image 122
FAHID Avatar answered Oct 11 '22 03:10

FAHID