【发布时间】:2022-01-17 10:37:45
【问题描述】:
我目前有一个结构化数据库,例如
return new Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
auto: true
},
name: {type: String, unique: false, required: true},
criteria: [
{
_id: {
type: mongoose.Schema.Types.ObjectId,
auto: true
},
category: {type: String, required: false},
links: {type: [String], required: false, default: []},
dateOfEntry: {
type: Date,
default: new Date(),
required: true
},
lastUpdated: {
type: Date,
default: new Date(),
required: true
}
}
],
isActive: {type: Boolean, required: false, default: true}});
样本数据
[
{
"name": "item1",
"criteria": [
{
"category": "category_A",
"links": [
"link_issue1",
"link_issue2",
"link_issue3"
]
},
{
"category": "category_B",
"links": [
"link_issue1",
"link_issue2"
]
},
]
},
{
"name": "item2",
"criteria": [
{
"category": "category_C",
"links": []
},
]
}
]
所以现在,我想将链接的数据类型从数组更改为字符串并更新现有数据
我的预期喜欢
[
{
"name": "item1",
"criteria": [
{
"category": "category_A",
"links": "link_issue1,link_issue2,link_issue3"
},
{
"category": "category_B",
"links": "link_issue1,link_issue2"
},
]
},
{
"name": "item2",
"criteria": [
{
"category": "category_C",
"links": ""
},
]
}
]
我的数据库有大约 500-1000 条记录需要更新。那么我们可以通过 MongoDB shell 更新它们吗? 非常感谢您的帮助。
【问题讨论】:
标签: mongodb mongoose mongodb-query