【问题标题】:Mongoose-How to specify more than one attribute value in querys?Mongoose-如何在查询中指定多个属性值?
【发布时间】:2020-08-30 07:35:42
【问题描述】:

我有这个猫鼬查询,我想添加条件 estadoPedido:"Agendado" 到它?我该怎么做?

Request.countDocuments(
    { estadoPedido: "Pendente", paciente: req.body.paciente }

【问题讨论】:

    标签: node.js express mongoose


    【解决方案1】:

    如果我理解你的问题,你需要搜索有

     - estadoPedido = 'Pendente' or 'Agendado'
     - and paciente = req.body.paciente
    

    你可以使用 $in 操作符,像这样

    Request.countDocuments({ 
        estadoPedido: { $in: ['Pendente', 'Agendado'] }, 
        paciente: req.body.paciente 
    })
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      你也可以添加多个 where 子句

      Request.countDocuments()
                  .where("estadoPedido")
                  .in(['Pendente', 'Agendado'])
                  .where("prop2")
                  .in(["val1","val2"])
      

      【讨论】:

        猜你喜欢
        • 2017-06-04
        • 2021-10-23
        • 2015-08-24
        • 2014-10-08
        • 1970-01-01
        • 2020-03-24
        • 2013-11-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多