Best schema for this

I have a mongodb schema. I wonder if there is a better approach for this schema.

question: {
    type: String,
    required: true,
  },
  image1: {
    type: String,
    required: true,
  },
  image2: {
    type: String,
    required: true,
  },
  imageOneVotes: {
    type: Number,
    default: 0,
  },
  imageTwoVotes: {
    type: Number,
    default: 0,
  },
  votes: {
    type: Number,
    default: 0,
  }
1 Like

and

tells me you should be using an array. Even if you have only 2 elements. You can do things with array that you cannot do easily with image1 and image2.

and

tells me that you should group together under an object the things that are related. You could easily manipulate what is related to an image if everything related to this image is under the same object.

1 Like

I am new myself, but it seems this question hasn’t been closed for 11 days so maybe the previous answer wasn’t clear enough (understandably, it seems a bit bare-bones for a beginner)
I think what Steeve meant to say may be something along the lines of this:

question: {
    type: String,
    required: true,
  },
images:{
  [
    {
      type: String,
      required: true,
      VotesType: Number   --> see if you really need this - the votes are always going to be a number, no?
      VotesDefault: 0,
    },
    {
      type: String,
      required: true,
      votes:        --> Alternative option for the votes
        {
          type: Number,
          default: 0,
        }
    }
  ]
}

I am probably not doing this right, but I’m trying to give an example using the idea that Steeve put forward according to what I know… which is just about nothing, but I know how JSON works, so I hope this helps you at least in finding a new route to try things. Basically the idea I got from his post was “make an array of the images and put the votes inside of that”.

1 Like

So that was literally my first answer in this forum, and I obviously messed up how to represent code, I apologize… can’t seem to find a way to edit it after the fact, so far.