I'm trying to create a new document using javascript for mongoDB database, and add values to deeply nested properties in the schema. Specifically i'm trying to add values to the taskItem, highlight, and identifier properties on task. Right now my schema looks like this
const todoTaskSchema = new mongoose.Schema({
username: String,
password: String,
task: [
{
taskItem: String,
highlight: {type: Boolean, default: false},
identifier: Number,
}],
subTask: [
{
pointer: Number,
tasks: Array,
},
]
})
My destructured properties look like this.
const { username, password, task: [ { taskItem: taskName, highlight: starred, identifier} ] } = req.body
I'm using the .create method to create the document. It's argument looks like this:
dbModel.create({ taskName, starred, identifier })
If I do this, and make a post request from postman using something like
{
"username": "Bruce Lee",
"password": "enter the dragon",
"task": [
{
"taskItem": {
"type": "figure out error",
"highlight": true,
"identifier": 1
},
"subTask": [
{
"subTaskItem": {
"pointer": 1,
"type": "abc",
"tasks": [1, 2, 3] }
}]
}]
}
the output on mongoDb is:
_id: 62ba2300c854b603578af1ac
task:Array
subTask:
Array
__v:0
can anyone tell me how to access the correct properties in the schema in order to correctly fill out the document using .create()?