【发布时间】:2022-11-27 12:20:13
【问题描述】:
我正在尝试做一个 pullFilter 并且可以让它在复杂类型上工作。
await _Collection.UpdateOneAsync(
Builders<Descriptor>.Filter.Eq(d => d.Id, id),
Builders<Descriptor>.Update
.Set(d => d.UpdatedBy, actioner)
.Set(d => d.UpdatedOn, DateTime.Now)
.PullFilter(d => d.Options, "Remove this one")
);
但是,Options 是一个字符串值数组,我无法让它删除值“Remove this one”:
{
"Name" : "Test",
"Type" : NumberInt(1),
"Options" : [
"Testing",
"Tested",
"Remove this one"
]
}
这是我的错误信息:
message": "JSON reader was expecting a value but found 'Remove'."
我也试过这个:
await _Collection.UpdateOneAsync(
Builders<Descriptor>.Filter.Eq(d => d.Id, id),
Builders<Descriptor>.Update
.Set(d => d.UpdatedBy, actioner)
.Set(d => d.UpdatedOn, DateTime.Now)
.PullFilter(d => d.Options, d => d == "Remove this one")
);
导致此错误:
"message": "{document} is not supported."
【问题讨论】: