I am trying to create a model for a collection whose objects look like below,how do declare clonedChangesdetailslist in mongoose which is a list of dictionaries?[String] doesn't seem to be the right thing?
{
"_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 model
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);
You can define clonedChangesdetailslist as an Array of Objects.
Try this :
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 },
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With