Filter the Collection in DB instead of Memory
I\'m having a Model Class, Save it in a MongoDB Collection then Query the same as per my expec
You have several int for your approach.
first you are using collectionEmpInfo.InsertOne(EmpInfo);
i am assuming you want to use InsertMany
instead.
as for filtering over the collection you have to know that your filter will affect if the whole object is retrieved, so adding a filter on an embedded array within an entity will not filter the array but determine if the whole object is retrieved or not based on whether it matches the query condition on the embedded array. My suggestion is to only apply the filter over the employees in the query and filter the result set in memory.
var filter = filterBuilder.Eq("IsLive", true);
var results = await collection.FindAsync(filter).ToListAsync();
now filter the results collection in memory as in
var filteredResults = results.ForEach(employee => employee.EmpMobile = employee.EmpMobile.Where(mob => mob.isLive).ToList());