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