MongoDB Schema: Array with multiple fields? -
I am trying to make users schema to store my favorite shoes. Right now, I have the following schema:
Local: {email: string, password: string,}
How do I add an array of shoes like When the user clicks on a button, will the database add shoe brand and size to user object? Something like this:
Favorite_short: {Brand: xxxx Size: xxxx, Brand: xxxxx Size: xxxxxx}
How do I do this for each user / what does schema look like?
Your schema will look like this:
{usernam: string , Email: string, password: string, favorite_shorts: [{brand: string, size: int}, {brand: string, size: int}]}
you do not have to do this before Preferred_Shore
field
.users.update ({usernam: "user name"}, {$ addToSet: {favorite_shoes: {brand: "adidas", size: 12}}});
Comments
Post a Comment