0

can someone help me?

I'm trying to update my Mongoose Schema and add to it an Array like this : I want to add to my ProductSchema the "attribute" ( I don't know how we call this, sorry ^^') description and in this description, you have multiple attributes lile brand, model, size, color, ...

I did something like this but (I don't think it worked) :

...
    description: [
        { brand: String },
        { model: String },
        { size: String },
        { color: String },
        { year: Number },
        { State: String }
    ]
...

Thank's for your time !

UPDATE:

In fact, I don't need an array for the description, that was a stupid question ^^'

I can do something like this :

...
    description: {
        brand: String,
        model: String,
        size: String,
        color: String,
        year: Number,
        State: String
    }
...
2
  • 1
    You can use "property" instead of "attribute" if you find it more explicit. Commented Mar 9, 2019 at 16:55
  • thank's for the precision ! Commented Mar 9, 2019 at 16:55

1 Answer 1

1

Sure, you don't need an array if there is only one "decription" in your document schema.

However, if you need to store multiple descriptions, you can use :

...
description: [{
    brand: String,
    model: String,
    size: String,
    color: String,
    year: Number,
    State: String
}]

In your first attempt, you've made each property of your object an object itself.

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.