0

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()

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.