I have below document, I am trying to search an element which is inside the nested document "ids",
If element is found return value bool or count. I tried with Mongodb query but not sure how to write a query for an array elements.
error :-Operator == cannot be applied to operands of type 'string[]' and 'string'
foreach (var req in _addUpdateRailsObjectInfoRequest.ids)
{
string value=req.id
var isIdExists = Builders<RailsData>.Filter.And(
Builders<RailsData>.Filter.ElemMatch(c => c.content.queryInclude, c => c.type == req.type),
Builders<RailsData>.Filter.ElemMatch(c => c.content.queryInclude, c => c.ids == value));
}
//Error at last line near c.id==value. Operator == cannot be applied to operands of type 'string[]' and 'string'
{
"_id" : ObjectId("5c2d3e700aff6771ebfc88ea"),
"name" : "Toyota",
"content" : {
"queryInclude" : [
{
"type" : "departments",
"ids" : [
"21",
"18",
"19",
"29",
"30"
]
}
]
}
}
//
public class RailsData
{
public string name { get; set; }
public content content { get; set; }
}
public class content
{
public List<queryInclude> queryInclude { get; set; }
}
public class queryInclude
{
public string type { get; set; }
public string[] ids { get; set; }
}
Builders<RailsData>.Filter.ElemMatch(c => c.content.queryInclude, c => c.ids.Contains(value));?