代码之家  ›  专栏  ›  技术社区  ›  koque

为什么mongodb aggregation$match没有返回预期结果?

  •  0
  • koque  · 技术社区  · 7 年前

    我正在建立一个聚合管道。以下各项单独或同时产生预期结果:

    let products = await Product.aggregate([
      { '$match': { brand: [Object] } },
      { '$match': { '$expr': [Object] } } ])
    

    下面的$match语句不生成任何数据,即使集合中有符合条件的数据。

    let products = await Product.aggregate([ { '$match': { rating: 4 } } ])
    

    收集的样本数据:

    { _id: 5a295aef734d1d69e07ee6dd, rating: '4'},
    { _id: 5a296199734d1d69e07eec27, rating: '4'}
    
    0 回复  |  直到 7 年前
        1
  •  1
  •   Bishaka Samuel    7 年前

    不匹配的数据类型。。您正在发送一个整数,但数据库中存储的是字符串。。只需添加引号:)

    推荐文章