在Mongo Atlas UI中使用聚合器

发布于 2025-02-06 06:57:56 字数 535 浏览 2 评论 0原文

我正在使用UI中使用Mongo Atlas的总管道,并且可以将其钉住一点,但是我无法在特定领域进行区域。

我已经对其进行过滤直到现在,我只想将ID的区别作为列表,例如我们在SQL中获得的列表。

从表中选择不同的(id)。

orderReceivedBy: “something”
ID: 150435
    
country: “UAE”
    
createdAt: 2022-02-14T09:55:59.393+00:00

orderReceivedBy: “something”
ID: 150435
    
country: “IN”
    
createdAt: 2022-02-14T09:55:59.393+00:00

orderReceivedBy: “something”
ID: 150435
    
country: “NL”
    
createdAt: 2022-02-14T09:55:59.393+00:00

结果应为

UAE
IN
NL

I am using aggregate pipeline in mongo atlas, using UI, and I am able to nail down it a bit , however I am not able to do district on particular field.

I have filtered it until below now I want only distinct of ID as a list like how we get in sql.

select distinct(ID) from table.

orderReceivedBy: “something”
ID: 150435
    
country: “UAE”
    
createdAt: 2022-02-14T09:55:59.393+00:00

orderReceivedBy: “something”
ID: 150435
    
country: “IN”
    
createdAt: 2022-02-14T09:55:59.393+00:00

orderReceivedBy: “something”
ID: 150435
    
country: “NL”
    
createdAt: 2022-02-14T09:55:59.393+00:00

Result should be

UAE
IN
NL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2025-02-13 06:57:59

您可以在聚合管道中获得唯一国家/地区的一种方法是使用“ $ group”阶段。

db.collection.aggregate([
  {
    "$group": {
      "_id": null,
      "countries": {
        "$addToSet": "$country"
      }
    }
  }
])

示例输出:

[
  {
    "_id": null,
    "countries": [
      "UAE",
      "NL",
      "IN"
    ]
  }
]

尝试一下 mongoplayground.net.net

One way you can get the unique countries in an aggregation pipeline is by using a "$group" stage.

db.collection.aggregate([
  {
    "$group": {
      "_id": null,
      "countries": {
        "$addToSet": "$country"
      }
    }
  }
])

Example output:

[
  {
    "_id": null,
    "countries": [
      "UAE",
      "NL",
      "IN"
    ]
  }
]

Try it on mongoplayground.net.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文