【发布时间】:2020-07-03 20:02:21
【问题描述】:
有一个包含记录的集合,需要将列的布尔值转换为字符串:
[
{
_id: "bmasndvhjbcw",
name: "lucas",
occupation: "scientist",
passed_phd: true,
age: 55,
location: "texas",
},
{
_id: "bmasndvhjbcx",
name: "mark",
occupation: "scientist",
age: 45,
passed_phd: true,
location: "texas",
},
{
_id: "bmasndvhjbca",
name: "stuart",
occupation: "lab assistant",
age: 25,
passed_phd: false,
location: "texas",
},
{
_id: "bmasndvhjbcq",
name: "cooper",
occupation: "physicist",
age: 69,
passed_phd: false,
location: "texas"
}
]
如何将记录的布尔值更改为字符串。
passed_phd 中具有 true(boolean) 的值应转换为 "yes"(string)
passed_phd 中包含 false(boolean) 的值应转换为“no”(string)
[
{
_id: "bmasndvhjbcw",
name: "lucas",
occupation: "scientist",
passed_phd: "yes",
age: 55,
location: "texas",
},
{
_id: "bmasndvhjbcx",
name: "mark",
occupation: "scientist",
age: 45,
passed_phd: "yes",
location: "texas",
},
{
_id: "bmasndvhjbca",
name: "stuart",
occupation: "lab assistant",
age: 25,
passed_phd: "no",
location: "texas",
},
{
_id: "bmasndvhjbcq",
name: "cooper",
occupation: "physicist",
age: 69,
passed_phd: "no",
location: "texas"
}
]
mongodb 4.0 版 .
【问题讨论】:
标签: mongodb aggregation-framework aggregate aggregation