如何创建带有字典列表的猫鼬模型?
how to create a mongoose model with list of dictionaries?
我正在尝试为对象如下所示的集合创建模型,如何在 mongoose 中声明 clonedChangesdetailslist
这是一个字典列表?[String]
似乎不是正确的事情?
{
"_id" : ObjectId("6d17d2dd84d4734eea82989f"),
"orgChange" : "62369696",
"created_on" : ISODate("2019-06-29T14:06:20.686Z"),
"clonedChangesdetailslist" : [
{
"clonedChange" : "62392779",
"clonedStatus" : "PASS",
"clonedChangeFinalStatus" : "PASS",
"updatedFailedReason" : "N/A",
"clonedChangeFinalStatusReason" : "N/A",
"updateStatus" : "PASS",
"clonedStatusfailReason" : "N/A"
},
{
"clonedChange" : "62392793",
"clonedStatus" : "PASS",
"clonedChangeFinalStatus" : "PASS",
"updatedFailedReason" : "N/A",
"clonedChangeFinalStatusReason" : "N/A",
"updateStatus" : "PASS",
"clonedStatusfailReason" : "N/A"
}
]
}
mongodb 型号
const mongoose = require('mongoose');
const { Schema } = require('mongoose');
const change_cloning_Schema= new Schema({
orgChange: String,
created_on: String,
clonedChangesdetailslist:[String]
},
{
collection: 'change_cloning',
timestamps: { createdAt: true, updatedAt: true },
});
module.exports = mongoose.model('change_cloning', change_cloning_Schema);
您可以将 clonedChangesdetailslist
定义为 Array of Objects
。
试试这个:
const change_cloning_Schema= new Schema({
orgChange: String,
created_on: String,
clonedChangesdetailslist:[{
clonedChange : String,
clonedStatus : String,
clonedChangeFinalStatus : String,
updatedFailedReason : String,
clonedChangeFinalStatusReason : String,
updateStatus : String,
clonedStatusfailReason : String
}]
},
{
collection: 'change_cloning',
timestamps: { createdAt: true, updatedAt: true },
});
我正在尝试为对象如下所示的集合创建模型,如何在 mongoose 中声明 clonedChangesdetailslist
这是一个字典列表?[String]
似乎不是正确的事情?
{
"_id" : ObjectId("6d17d2dd84d4734eea82989f"),
"orgChange" : "62369696",
"created_on" : ISODate("2019-06-29T14:06:20.686Z"),
"clonedChangesdetailslist" : [
{
"clonedChange" : "62392779",
"clonedStatus" : "PASS",
"clonedChangeFinalStatus" : "PASS",
"updatedFailedReason" : "N/A",
"clonedChangeFinalStatusReason" : "N/A",
"updateStatus" : "PASS",
"clonedStatusfailReason" : "N/A"
},
{
"clonedChange" : "62392793",
"clonedStatus" : "PASS",
"clonedChangeFinalStatus" : "PASS",
"updatedFailedReason" : "N/A",
"clonedChangeFinalStatusReason" : "N/A",
"updateStatus" : "PASS",
"clonedStatusfailReason" : "N/A"
}
]
}
mongodb 型号
const mongoose = require('mongoose');
const { Schema } = require('mongoose');
const change_cloning_Schema= new Schema({
orgChange: String,
created_on: String,
clonedChangesdetailslist:[String]
},
{
collection: 'change_cloning',
timestamps: { createdAt: true, updatedAt: true },
});
module.exports = mongoose.model('change_cloning', change_cloning_Schema);
您可以将 clonedChangesdetailslist
定义为 Array of Objects
。
试试这个:
const change_cloning_Schema= new Schema({
orgChange: String,
created_on: String,
clonedChangesdetailslist:[{
clonedChange : String,
clonedStatus : String,
clonedChangeFinalStatus : String,
updatedFailedReason : String,
clonedChangeFinalStatusReason : String,
updateStatus : String,
clonedStatusfailReason : String
}]
},
{
collection: 'change_cloning',
timestamps: { createdAt: true, updatedAt: true },
});