匹配MongoDB中的两列

2024-05-16 19:07:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两列statedate,我想通过在python中传递动态值来匹配它,下面是我使用的查询,但它不返回任何值

enter image description here

请告知以下SQL查询的MongoDB查询:

select sum(cases) from COVID19_DB.COVID19.NYTIMES_US_STATES where state='Wyoming' and date='2020-05-23' order by date asc;

谢谢, 苏梅什


Tags: fromdbsqldatemongodb动态whereselect
1条回答
网友
1楼 · 发布于 2024-05-16 19:07:25

阅读您的评论,我知道您只需要一个匹配两个值的简单find查询

我想当你说“column”时,你想说“field”,所以你只需要像这样匹配两个值:

db.collection.find({
  "state": "Wyoming",
  "date": "2020-05-23"
})

检查此example

但是,如果您使用的是聚合,那么您可以以this的方式使用$match

db.collection.aggregate([
  {
    "$match": {
      "state": "Wyoming",
      "date": "2020-05-23"
    }
  }
])

正如您所看到的,匹配多个“列”只能由您想要的所有值查找

相关问题 更多 >