[CSHARP-495] The "In" operator matches the whole element in the input array. So a query with "In" with "Contains" is not possible. Created: 14/Jun/12  Updated: 04/May/20  Resolved: 04/May/20

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

Type: New Feature Priority: Major - P3
Reporter: Sunil Raj Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

software platform


Issue Links:
Depends
Duplicate
is duplicated by CSHARP-494 Support Regular Expressions for $in q... Closed
Related
is related to CSHARP-493 LINQ - Allow Regex Usage inside $all Backlog

 Description   

Please refer my question: ``Is there an option to perform the "In" operation on strings?`` for more details:
https://jira.mongodb.org/browse/CSHARP-494

There is no equivalent to this mongo query in c# driver to linq:
db.Feeds.find({ShortDescription:{$in:[/sunil/, /raj/]}})

The Predicatebuilder wraps the string content with double quotes, which affects the result. Please fix/ add this feature.

Thanks..



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

Thanks Craig for your input. I will implement the same and will be waiting too

Comment by Craig Wilson [ 15/Jun/12 ]

You can always build the $in query manually as well while you are waiting. Syntax might be a little off here, but this should work. $in will use an index better than $or.

new QueryDocument("fieldName", new BsonDocument
{

{ "$in", new BsonArray(searchwordlist.Select(x => new Regex(x, RegexOptions.IgnoreCase)) }

});

Comment by Sunil Raj [ 15/Jun/12 ]

Craig,
I was able to find an alternative to attain my objective.
I used the Query.Or().Inject() with a IMongoQuery with BSonValue as a Regular expression type.
My code block is given below:

if (!string.IsNullOrEmpty(tags))
{
var searchwordlist = tags.ToLower().Split(new char[]

{ ',' }

, StringSplitOptions.RemoveEmptyEntries).ToList();

List<IMongoQuery> queries = new List<IMongoQuery>();
foreach (var item in searchwordlist)

{ queries.Add(new QueryDocument(new BsonElement("ShortDescription", new Regex(item, RegexOptions.IgnoreCase)))); }

var queriesArray = queries.ToArray();
feeds = feeds.Where(f => Query.Or(queriesArray).Inject());
}

//Here I am creating an array of IMongoQuery by iterating through the list of strings to be passed as query.

This seems to be performing a bit slow though. So waiting for your update on the new feature.

Comment by Craig Wilson [ 14/Jun/12 ]

I'm not sure I following your question: "I was wondering if this was possible using other options such as regular expressions". Could you please restate or clarify?

Comment by Sunil Raj [ 14/Jun/12 ]

I was wondering if this was possible using other options such as regular expressions. Anyways, thanks for the update. Eagerly waiting for the feature.
Sunil.

Comment by Craig Wilson [ 14/Jun/12 ]

I have changed this from a Bug to a Feature Request as the code is performing properly, we just haven't implemented this particular item.

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