[
{
"_id": {
"$oid": "61c474fd740cd6a46a7e8166"
},
"GroupIds": [
{
"$oid": "31c482ff6836e438631995ed"
},
{
"$oid": "11c482ff6836e438631995ee"
},
{
"$oid": "61bb96fb4c3d7106f5b9587a"
}
],
"Username": "Test"
},
{
"_id": {
"$oid": "61c474fd740cd6a46a7e8166"
},
"GroupIds": [
{
"$oid": "15c482ff6836e438631995ed"
},
{
"$oid": "61c482ff6836e438631995ee"
},
{
"$oid": "61bb96ee4c3d7106f5b95879"
}
],
"Username": "Test1"
},
{
"_id": {
"$oid": "21c474fd740cd6a46a7e8166"
},
"GroupIds": [
{
"$oid": "61c482ff6836e438631995ed"
},
{
"$oid": "61c482ff6836e438631995ee"
},
{
"$oid": "61bb96ee4c3d7106f5b95879"
}
],
"Username": "Test2"
},
{
"_id": {
"$oid": "31c474fd740cd6a46a7e8166"
},
"GroupIds": [
{
"$oid": "61c482ff6836e438631995ed"
},
{
"$oid": "61c482ff6836e438631995ee"
},
{
"$oid": "61bb96fb4c3d7106f5b9587a"
}
],
"Username": "Test3"
}
]
Hello, I want to make multiple group based searches in mongo db,
I can make a single group based Search
public async Task<List<List<ObjectId>>> UsersByGroupIdV3(List<List<string>> targetGroupses)
{
List<FilterDefinition<User>> query= new List<FilterDefinition<User>>();
foreach (var targetGroups in targetGroupses)
{
if (targetGroups[0] != "allcountry")
{
query.Add(Builders<User>.Filter.Eq(x => x.GroupIds[0], new ObjectId(targetGroups[0])));
}
if (targetGroups[1] != "allCity")
{
query.Add(Builders<User>.Filter.Eq(x => x.GroupIds[1], new ObjectId(targetGroups[1])));
}
if (targetGroups[2] != "allDistrict")
{
query.Add(Builders<User>.Filter.Eq(x => x.GroupIds[2], new ObjectId(targetGroups[2])));
}
}
var match = Builders<User>.Filter.And(query);
var users = await _userRepository.Find(match);
var group = users.Result.Select(i => i.GroupIds);
return group.ToList();
}
There is a list of nested groups in the targetGroupses parameter
Example
[{["31c482ff6836e438631995ed","11c482ff6836e438631995ee","61bb96fb4c3d7106f5b9587a"]},{["15c482ff6836e438631995ed","61c482ff6836e438631995ee","61bb96ee4c3d7106f5b95879"]}]
var match = Builders.Filter.And(query);
If there is 1 list, it works fine, but if there is more than 1, how can I run the query?
I want to bring those in the America, Alaska, College or Germany Hessen Kreis groups
{[{"America", "Alaska", "College"}],[{"Germany", "Hessen", "Kreis"}]}
I want to fetch what’s in this group from mongo db with c#