I need to search the contents in all documents, in particular in the mongodb collection in .net mvc. I tried using the mongodb shell by creating the index successfully, as here.
db.collection_name.createIndex( { subject: "text" } )
db.collection_name.find( { $text: { $search: "search_word" } } )
It works great. but when I put it in .net, it gives me an error. I searched for it and got the following indexing solution.
collection.EnsureIndex(new IndexKeysBuilder().Ascending("subject"));
now how can i run this query db.collection_name.find( { $text: { $search: "coffee" } } ).
I am trying to use .net as follows.
collection.CreateIndex("subject":"text");
var query = collection.Find({ $text: { $search: "coffe" }});
but I get an error in the first line "presents the text as a unicode series .... syntax error"
2nd line error "There are no arguments that match the required formal parameters" AND "unexpected symbol $".
Any suggestion would be appreciated.