简体   繁体   中英

Search multiple Mongo columns for multiple entries

I have made a nice pageing system that is ajax dynamic with .net, mongodb, and twitter bootstrap. Everything works great but now I would like to have a text box where the user can search and ajax/mongo driver search all fields of a collection and return the results, a perfect example of my goal can be seen here at the datatables plugin. I have tried a few things such as combing all of the columns with an or:

Query.Or(
    Query.Matches("Name", new BsonRegularExpression(query, "i")),
    Query..Matches("Facility.Name", new BsonRegularExpression(query, "i")),
    etc...
)

Which I suppose in theory is the way you could do it, however I was hopeing for a solution a little more universal. When you use the data tables plugin i linked it will search all data no matter what and organize it properly (i realize this is html not a DB) but is there a systematic way to do this with MongoDB? Any one have any pointers?

MongoDB text indexes will allow you to create a text index on specific fields within a document or on all fields within each document. After you've created the index you can use the $text operator to performa a search.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM