查询后,我想将数组定义为数组,例如从["one", "two", "three"]
到"one, two, three"
。我试图遍历查找结果,可以加入数组,但是将结果设置为长度为1的数组,例如--["one, two three"]
const ModelSchema = new mongoose.Schema({
field: {type: Array }
})
查询和循环:
let result = await collection.find()
for (let j = 0; j < result.length; j++) {
result[j].field = result[j].field.join(", ")
}
结果:
["one, two, three"]
尽管在架构中将该字段定义为数组,但我可以将该字段转换为字符串吗?
我尝试克隆result
,但是输出保持不变。