【发布时间】:2021-04-16 04:57:54
【问题描述】:
我在构建过滤器以按条件在嵌套数组中获取对象时遇到问题。
我的模型是:
public class ProductPriceInStore
{
[BsonId]
public ObjectId Id { get; set; }
public ObjectId store { get; set; }
public ObjectId product { get; set; }
public string measurementUnit { get; set; }
public IList<ProductPrices> prices { get; set; }
}
public class ProductPrices
{
public double? actualPrice { get; set; }
public double? originalPrice { get; set; }
}
我想要做的是找到所有 ProductPriceInStore,其中包含 ProductPrice 且实际价格大于 originalPrice
我在我的项目中使用 nugget MongoDB.Driver 2.7.3
【问题讨论】:
-
看
ElemMatch。 -
我试着像这样使用它 var filter = Builders
.Filter.ElemMatch(y => y.prices, x => x.actualPrice > x.originalPrice);但它给了我错误'不支持的过滤器:({document}{actualPrice} > {document}{originalPrice})。我将不得不进一步研究 elementMatch
标签: c# .net mongodb mongodb.driver