[CSHARP-494] Support Regular Expressions for $in query builders on strings Created: 14/Jun/12  Updated: 05/Apr/19  Resolved: 14/Jun/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Sunil Raj Assignee: Unassigned
Resolution: Done Votes: 0
Labels: commands, question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CSharp Driver Linq to MongoDB


Issue Links:
Duplicate
duplicates CSHARP-495 The "In" operator matches the whole e... Closed

 Description   

In operators for query builders and Linq extension should take regular expressions as arguments when the operator is a string.

Original report:
--------------------------------
Could you please verify if there is an option to build a linq query equivalent to the mongo query:

db.Feeds.find({ShortDescription:{$in:[/sunil/, /raj/]}})

I have tried:
MongoCollection<BsonDocument> feedscollection = _db.database.GetCollection<BsonDocument>("Feeds");
var feeds = (from f in feedscollection.AsQueryable<Feeds>()
select f);
string tags="1)Lorem ipsum sunil dolor sit amet, 2)Maecenas raj pretium laoreet nibh, 3)a rhoncus turpis cursus gravida";
var searchwordlist = tags.ToLower().Split(new char[]

{ ',' }

, StringSplitOptions.RemoveEmptyEntries).Select(s => string.Format("/

{0}

/", s)).ToList();
feeds = feeds.Where(f => f.ShortDescription.In(searchwordlist));
//With the mongo query I am getting the first and second sentence. But when I go with the linq -> mongo query, I am not getting any results.



 Comments   
Comment by Sunil Raj [ 14/Jun/12 ]

Answer to my own question.

The PredicateBuilder in the c# driver converts the query:
feeds = feeds.Where(f => f.ShortDescription.In(searchwordlist));

to:
{ShortDescription:{"$in":["/sunil/", "/raj/"]}}
Please note the double quotes(") around the strings. These are the spoilers. This query matches for the whole string.
So let me put this as a feature/bug.
Thanks..

Comment by Sunil Raj [ 14/Jun/12 ]

Edit:
_____

string tags="sunil, raj";
//searchwordlist has these strings as: /sunil/ /raj/
//Search is performed on the data:
1)Lorem ipsum sunil dolor sit amet
2)Maecenas raj pretium laoreet nibh
3)a rhoncus turpis cursus gravida

Generated at Wed Feb 07 21:37:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.