从mongo BD中的facet命令获取信息

发布于 2025-01-13 04:57:57 字数 521 浏览 1 评论 0原文

我正在尝试从管道中提取名称列表,其中我得到以下内容:

 command_5 = {"$facet": {
        "list_of_station_names": my_query_1}}

并得到结果:

list_of_station_names  :  [{'desc': 'Sip Ave'}, {'desc': 'Vesey Pl &; River Terrace'}, {'desc': 'Murray St &; West St'},{'desc': 'E 81 St &; York Ave'}] 

但我需要列表中的结果不带属性名称“desc”,如下所示:

 list_of_station_names  :  ['Sip Ave', 'Vesey Pl &; River Terrace','Murray St &; West St','E 81 St &; York Ave']

I'm trying to extract a list of names from a pipeline, where I get the following:

 command_5 = {"$facet": {
        "list_of_station_names": my_query_1}}

And get as result:

list_of_station_names  :  [{'desc': 'Sip Ave'}, {'desc': 'Vesey Pl &; River Terrace'}, {'desc': 'Murray St &; West St'},{'desc': 'E 81 St &; York Ave'}] 

but I need the results in a list without the attribute name "desc", like this:

 list_of_station_names  :  ['Sip Ave', 'Vesey Pl &; River Terrace','Murray St &; West St','E 81 St &; York Ave']

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

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

发布评论

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

评论(1

时常饿 2025-01-20 04:57:57

您只能在刻面之后映射它。

db.collection.aggregate([
  {
    $facet: {
      list_of_station_names: []
    }
  },
  {
    $set: {
      list_of_station_names: {
        $map: {
          input: "$list_of_station_names",
          as: "n",
          in: "$n.desc"
        }
      }
    }
  }
])

mongoplayground

You can only map it after facet.

db.collection.aggregate([
  {
    $facet: {
      list_of_station_names: []
    }
  },
  {
    $set: {
      list_of_station_names: {
        $map: {
          input: "$list_of_station_names",
          as: "n",
          in: "$n.desc"
        }
      }
    }
  }
])

mongoplayground

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