gpt4 book ai didi

node.js - 如何创建带有字典列表的 Mongoose 模型?

转载 作者:可可西里 更新时间:2023-11-01 10:36:14 31 4
gpt4 key购买 nike

我正在尝试为对象如下所示的集合创建模型,如何在 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定义为对象数组

试试这个:

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 },
});

关于node.js - 如何创建带有字典列表的 Mongoose 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56830511/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com