When I attempt to do so I the rest to the data is posted but the array remains empty
my Schma looks like this
const mongoose = require('mongoose');
const DocumentSchema = mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
},
dateCreated: String,
title: String,
// ID of the users that created the document
creatorId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
},
comment: [{ title: String, detail: String }]
});
module.exports = mongoose.model('myDocument', DocumentSchema);
My Post script in postman looks like this
{
"label":"Got More data",
"linkUrl":"www.google.com",
"title":"test 14",
"comment":[
{
"title":"hello",
"detail":"some detail"
}]
}
When I get the data that I have updated it looks like this
{
"_id": "5eb91c0e35eecb369696b9c5",
"title": "test 14",
"creatorId": "5d8856e5903a260588b77c30",
"user": "5d8856e5903a260588b77c30",
"dateCreated": "Mon May 11 2020 10:34:06 GMT+0100 (British Summer Time)",
"comment": [],
"__v": 0
}
OTHER THINGS I HAVE TRIED
I have tried changing the schema definition according to this post on Stack overflow How to define object in array in Mongoose schema correctly with 2d geo index
to this
comment : [{
title : String,
detail : String
}]
and this approach too
comment : {
"title":"A title",
"detail": "some random comment"
}
but I still get a blank array