You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'd like to implement the following using FluentMongo (this is a LINQPad query):
void Main()
{
MongoServer mongo = MongoServer.Create(new MongoConnectionStringBuilder() { Server = new MongoServerAddress("localhost") } );
MongoDatabase database = mongo["Demo"];
MongoCollection<Employee> employeeCollection = database.GetCollection<Employee>("Employees");
Employee emp1 = new Employee() { Name = "Bob" };
emp1.Departments.Add("Dep1");
emp1.Departments.Add("Dep2");
Employee emp2 = new Employee() { Name = "Binette" };
emp2.Departments.Add("Dep2");
emp2.Departments.Add("Dep3");
employeeCollection.InsertBatch(new[] { emp1, emp2 });
IEnumerable<Employee> searchResult =
employeeCollection
.Find(Query.In("Departments", BsonArray.Create(new [] { "Dep1", "Dep2" })));
searchResult.Dump(); // LINQPad dumps the result to the output.
employeeCollection.RemoveAll();
}
class Employee
{
public Employee()
{
Departments = new List<string>();
}
public ObjectId Id { get; set; }
public string Name { get; set; }
public List<string> Departments
{
get;
private set;
}
}
Intuitively, I would implement the query like this in FluentMongo, but I get a NotSupportException:
IEnumerable searchResult2 =
employeeCollection
.AsQueryable()
.Where(o => o.Departments.Intersect(new [] { "Dep1", "Dep2" }).Any());
Is there a better way to implement this kind of query in FluentMongo?
Thanks,
gabriel
The text was updated successfully, but these errors were encountered:
Hi,
I'd like to implement the following using FluentMongo (this is a LINQPad query):
Intuitively, I would implement the query like this in FluentMongo, but I get a NotSupportException:
IEnumerable searchResult2 =
employeeCollection
.AsQueryable()
.Where(o => o.Departments.Intersect(new [] { "Dep1", "Dep2" }).Any());
Is there a better way to implement this kind of query in FluentMongo?
Thanks,
gabriel
The text was updated successfully, but these errors were encountered: