title: How to define object in array with Mongoose/MongoDB
body: <p>I want to get these data structure:</p>
  <pre><code>{
  &quot;_id&quot;: 5ff7822037fbe047d8fa6496,
  &quot;user_id&quot;: 5ff7822037fbe047d8fa1234,
  &quot;todos&quot;[
            {
              &quot;task&quot;: &quot;Do something&quot;,
              &quot;complited: false
            }
         ]
  }
  </code></pre>
  <p>can't create array with object</p>
  <p>Here is my code but it does not work proparly</p>
  <pre><code>//file TodoList.js
  const mongoose = require('mongoose')
  const todo = require('../models/Todo')
  const TodoList = mongoose.Schema({
      user_id: String,
      todos: [Object]
  })
  
  module.exports = mongoose.model(&quot;TodoList&quot;, TodoList)
  </code></pre>
  <pre><code>//Todo.js
  const mongoose = require('mongoose')
  
  const Todo = mongoose.Schema(
      {task: String,
      complited: Boolean}
  )
  
  module.exports = mongoose.model(&quot;Todo&quot;, Todo)
  </code></pre>
  <pre><code>//file todos.js
  
  const express = require('express')
  const Todo = require('../models/Todo')
  const TodoList = require('../models/TodoList')
  const router = express.Router()
  
  
  router.post('/create', async (req,res)=&gt;{
      
      const newTodo = new Todo({
          task: req.body.task,
          complited: req.body.complited
      })
      const newTodoList = new TodoList({
          user_id: req.body.user_id,
          todos: [newTodo]
      })
      
      try {
          const savedTodoList =await newTodoList.save()
          res.json(savedTodoList)
      } catch (err) {
          res.status(400).json(err)
      }
  })
  module.exports = router
  </code></pre>
  <p>When i send req such</p>
  <pre><code>{
      &quot;user_id&quot;: &quot;5ff7822037fbe047d8fa6496&quot;,
      &quot;todos&quot;:[{&quot;task&quot;: &quot;Do something&quot;, &quot;complited&quot;: false}]
  }  
  </code></pre>
  <p>I got this</p>
  <pre><code>{
      &quot;todos&quot;: [
          {
              &quot;_id&quot;: &quot;5ffa1862a0431052b4111f80&quot;,
              &quot;__v&quot;: 0
          }
      ],
      &quot;_id&quot;: &quot;5ffa1862a0431052b4111f81&quot;,
      &quot;user_id&quot;: &quot;5ff7822037fbe047d8fa6496&quot;,
      &quot;__v&quot;: 0
  }
  </code></pre>
  <p>Can you help me create one worker schema instead of two or just fix these
  Thank you
  I searched web and stackoverflow but did find something good for me)</p>