这是代码:
ProjectionDefinition<Accountant> projDefAccountant = Builders<Accountant>.Projection
.Include(x => x.Id)
.Include(x => x.Name);
ProjectionDefinition<Client> projDefClient = Builders<Client>.Projection
.Include(c => c.Name)
.Include(c => c.Address)
.Include(c => c.Occupation);
IMongoCollection<Accountant> collection = mongoDatabase.GetCollection<Accountant>("accountants");
IMongoCollection<Client> foreignCollection = mongoDatabase.GetCollection<Client>("clients");
var results = collection.Aggregate()
.Project<Accountant>(projDefAccountant)
.Lookup<Accountant, Client, Accountant>(
foreignCollection: foreignCollection,
localField: ac => ac.BestClientsIds,
foreignField: c => c.Id,
@as: ac => ac.MyClients
).ToList().AsQueryable();
我可以使用第一个投影"projDefAccountant"
来限制我想要从"accountants"
集合中删除哪些字段。有没有办法"projDefClient"
在连接集合上强制执行投影,"clients"
以便连接不返回所有字段,而只返回"projDefClient"
? 谢谢。