在调用 UpdateOneAsync 时,使用此包装器:
public async Task<UpdateResult> UpdateDocument<T>(
string sCollectionName,
Expression<Func<T, bool>> filter,
UpdateDefinition<T> update,
bool bUpsert,
System.Threading.CancellationToken cancellationToken
)
{
IMongoDatabase db = _mongoClient.GetDatabase(_optionsMonitor.CurrentValue.databasename);
IMongoCollection<T> collection = db.GetCollection<T>(sCollectionName);
return await collection.UpdateOneAsync<T>(filter, update, new UpdateOptions() { IsUpsert = bUpsert }, cancellationToken);
}
像这样:
private async Task<Models.Errors> UpdateDbOnSyncServerToBoardUpdate(
CancellationToken cancel,
MongoDB.Bson.BsonDocument bsonDocConfigurationToUpdate,
DateTime dtUpdated,
string sId,
int iObjectId,
string sAppName,
string sModelName
)
{
MongoDB.Driver.UpdateResult updateResult = null;
Models.Errors errors = null;
try
{
updateResult = await _db.UpdateDocument<Models.Database.NodeBoardModel>(
Constants.NodeBoardCollectionName,
node => node.Id == sId &&
我收到 NotSupportedException:
不支持表达式树:{document}{RemoteBoard}{apps}.SingleOrDefault(app => (app.appname == "eACM")).objects.SingleOrDefault(model => (model.name == "tag" )).config_docs
我感觉我以错误的方式或以 MongoDb 不支持的方式使用 LINQ 关键字,但很难准确判断问题出在哪里。
慕森卡
相关分类