【问题标题】:Dynamic Match Query MongoDB动态匹配查询 MongoDB
【发布时间】:2019-09-14 16:20:40
【问题描述】:

如何使用 nodejs 或 typescript 中的变量动态编写这些表达式之一?

$match: {
          date: '9-8-2019',
          "info.tag": "Test"
        }

$match: { 
    $expr: {
      $and:[ { $eq: ["$price_id", "$$id"]}, { $eq: ["$tag", "Test"] }]
    }
}

【问题讨论】:

  • 值是动态的还是静态的?
  • 我希望能够动态设置 $match。
  • 是的,我知道,但是日期和标签值是否是动态的?
  • 是的,我希望它们是动态的。你会如何设置 $tag 呢?
  • 不清楚你想说什么?

标签: node.js mongodb typescript


【解决方案1】:

在这个帮助下尝试

$match: {
id: req.body.id,
$and: [{
    createdAt: {
        $gte: new Date(start)
    }
}, {
    createdAt: {
        $lte: new Date(end)
    }
}]

},

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 2021-04-06
    • 2016-02-26
    • 2021-08-01
    • 1970-01-01
    相关资源
    最近更新 更多