I am using Mongo CSharpDriver-2.0.0 version and IMongoCollection Async in my application. My data collection looks as shown in the figure attached(2.png).
Here I want to perform a Search operation on Categories, basically we will give comma separated list of Category Names and it should return a list of Records that are matching the categories that are provided as input.
To implement above functionality I am using the below code: This code works fine when I pass a single category.
var collection = _database.GetCollection<BusinessDeal>("BusinessDeals");
var filter = Builders<BusinessDeal>.Filter.Eq("Categories.CategoryName", categorylist) | Builders<BusinessDeal>.Filter.Eq("Accessgroups.AccessgroupName", groups);
var result = await collection.Find(filter).ToListAsync();
But my requirement is to get the records when I provide a Comma separated categories List. For that implementation I have implemented the following code:
var collection = _database.GetCollection<BusinessDeal>("BusinessDeals");
var filter = Builders<BusinessDeal>.Filter.AnyIn("Categories.CategoryName", categorylist.Split(',').ToArr()) |
Builders<BusinessDeal>.Filter.AnyIn("Accessgroups.AccessgroupName", groups.Split(',').ToArr());
var result = await collection.Find(filter).ToListAsync();
The above code is not returning any results and throwing error as “Not Yielded any Results” and Status message as “Failed”.