从 mongo BD 中的 facet 命令获取信息
Get information from facet command in mongo BD
我正在尝试从管道中提取姓名列表,我得到以下信息:
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']
只能映射到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"
}
}
}
}
])
我正在尝试从管道中提取姓名列表,我得到以下信息:
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']
只能映射到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"
}
}
}
}
])