I need to join 3 collections in aggregation with multiple $lookup
I tried in C# driver it allow me to $lookup User collection but can't perform second $lookup for Setting collection.
Anyone can help?
db.Transactions.aggregate([
{
$lookup:
{
from: "Account",
localField: "AccountId",
foreignField: "_id",
as: "Account"
}
},
{
$lookup:
{
from: "User",
localField: "UserId",
foreignField: "_id",
as: "User"
}
}
])
.match({
})
.project({})
here is the C# code:
var account = _dbClient.GetDatabase(_dbName).GetCollection<Account>("Accounts");
var user = _dbClient.GetDatabase(_dbName).GetCollection<User>("Users");
var transaction = _dbClient.GetDatabase(_dbName).GetCollection<Transaction>("Transactions");
var result = (from t in transaction.AsQueryable()
join a in account.AsQueryable() on t.AccountId equals a.Id
join u in user.AsQueryable() on t.UserId equals u.Id into userList
from acc in userList.DefaultIfEmpty()
where acc.CompanyName.ToLower().Contains(companyName) && c.CreatedDate >= fromDate && c.CreatedDate <= toDate
select new TransactionHistory
{
Id = t.Id,
CompanyName = acc.CompanyName,
UserId = u.UserId
FirstName = u.FirstName
}).ToList();
I got the error $project or $group does not support {document}. using Linq.
LINQ?.Contains()for Account collection. I tried inLinqbut it throws me the message sayContaints()is not supported.Contains(xyz)is certainly supported...not sure aboutContaints()...$lookup? Could you post a code snippet, also (if any) errors that you're getting?