this is the schema that I have now but I need to add more array as number 2, 3, 4
> const PostSchema = mongoose.Schema({ > navigation: { > 1: [ > > subSchema > ] > } })
example:
> { > "navigation": { > "1": [test] > "2":[test2] } > }
//post api
const post = new Post({ navigation: req.body.navigation }); response = { message: 'success', uuid: req.body.uuid } try { const savedPost = await post.save()
Advertisement
Answer
Just try to create a schema with an empty object like:
Schema
const PostSchema = mongoose.Schema({ navigation: {} })
so you can add multiple elements. But your data completely depends on what you are sending in your API request.