Voting APP: is mongoose strictly necessary?

Hi there!!

I am starting with the first full-stack app, and many questions are popping in my head.
I am not very experienced with DBs so I am having some troubles trying to understand the role that Mongoose has. I used rawly Mongodb for the API project and I was very confident with it, but when starting with this one I read that most of the campers made use of Mongoose. Are my next thought right about what is Mongoose task??

  • “Translate between your objects in code and the document representation of the data”. Summarizing JSON into BSON, right?

Assuming it what do you think about this schema?

{
    pollName: {
       type: String,
       required: true
    },
   creator: {
       type: String,
       required: true
   },
   createdTime: {
       type: Date,
       default: Date.now
   },
   pollOptions: [
   {
       value: { 
            type:String,
            required: true
        },
        voteCount: {
            type: Number,
            required: true
        }
  }],
  voters: [ { user: String } ]

}

Thanks in advance!!

1 Like

It just makes things a lot easier. Mongoose documentation says “Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.”

So you can make your first full-stack web app without mongoose, but it will probably be more time-consuming. You’ll also probably learn a lot more that way. It’s up to you. As my first full-stack app, I chose to go the easier route because it’s an already intimidating task.

3 Likes

Thanks :D, and what do you think about my schema? Did you implement one similar?

My schema looks just like yours, only I have additional array for voted IPs

2 Likes

Your schema is better than what I used.

1 Like

@elisecode247 @jenovs I read that is not recommendable to have arrays in MongoDb that could grow without limit. I was thinking about how to redesign the voters array, but I think it will be more productive to start with the app instead of thinking so much right?

Don’t overthink it :slightly_smiling_face: There are enough moving parts to keep you busy. These arrays won’t grow too much, but I also read that such arrays should not be inside a document.

2 Likes

Thank you @elisecode247 and @jenovs :smiley: