I'm working with NodeJS and MongoDB,
Actually I'm have a doubt about the datastructure that I'm using in MongoDB, currently I save my data in the database like this:
{
"_id" : ObjectId("4f9519d6684c8b1c9e72e367"),
"tipo" : "First Post on MongoDB",
"rates": {
"user": "5c981a0f8a76d426dc04619e",
"votation": 1
},
}
But the way that I want to store the data is in this structure:
{
"_id" : ObjectId("4f9519d6684c8b1c9e72e367"),
"tipo" : "First Post on MongoDB",
"rates": {
"5c981a0f8a76d426dc04619e":{
"votation": 1
}
},
}
I had been trying to save the data like in the last example, but I don't achieve it,
Here is the way as I have my const in NodeJS.
const post = {
tipo: body.tipo,
user: body.usuario,
duration: 25,
rates:
{
user: body.usuario,
votation: 1
}
};
And Here is how I have my model:
interface IPost extends Document {
tipo: String;
user: Object;
duration: number;
rates: Object;
}
Can someone explain me how can I do it please?
Regards.