I working with MongoDB driver and I have the following classes:
public class Transactions
{
public ObjectId Id { get; set; }
public int UserId { get; set; }
public int AccountId { get; set; }
public int SettingId { get; set; }
}
public class Account
{
public int Id {get; set;}
public int Name {get; set;}
}
public class User
{
public int Id {get; set;}
public int Name {get; set;}
}
public class Setting
{
public int Id {get; set;}
public int Name {get; set;}
}
And I want form this, depending of the input of user:
var docs = collection.Aggregate()
.Lookup("account", "AccountId", "_id", "asAccounts")
.Lookup("user", "UserId", "_id", "asUsers")
.Lookup("setting", "SettingId", "_id", "asSettings")
.As<BsonDocument>()
.ToList();
That is, if the user just wanna the relation with account, form this:
var docs = collection.Aggregate()
.Lookup("account", "AccountId", "_id", "asAccounts")
.As<BsonDocument>()
.ToList();
Or if him wanna the relation with account and user:
var docs = collection.Aggregate()
.Lookup("user", "UserId", "_id", "asUsers")
.Lookup("setting", "SettingId", "_id", "asSettings")
.As<BsonDocument>()
.ToList();
It I trying to do is form the query depending the needs of user. Just wanna know how to chain the methods in runtime.