To be able to use mongoose
, we create models with the help of a Schema
as:
const instanceSchema = new Schema(
{
_mid: {
type: String,
required: true,
},
created_by: {
type: String,
required: true,
},
stages: [
id: {
type: String,
required: true,
}
],
},
{ timestamps: true }
);
which we can use to store data such as:
{
_mid: "ONE",
created_by: "owner",
stages: [1,2,3,4]
}
but, what would be the Schema
for such a data:
{
_mid: "ONE",
created_by: "owner",
stages: {
1: {
"name": "one"
},
2: {
"name": "two"
}
.
. // more data
.
1000: {
"name": "oneThousand"
}
}
}