I have one mongodb schema (ChampionshipSchema) that accepts a multiple values :
tieBreak: [{
name: String,
priority : Number
}],
If I add one by one in this schema, it is OK, but if I try to add a list do values at the same time, I have an error.
Code to add in the schema :
function createTable (idChampionship, tieBreaks, callback) {
// tieBreaks is an array of tieBreak values
var query = { _id : idChampionship };
var newValues = {
$push: { tieBreak: tieBreaks }
};
Championship
.update(query, newValues)
.exec((err, result) => {
if(err) callback (false);
else {
if (result.nModified > 0) {
callback(true);
} else {
callback(false);
}
}
});
}
And the result is :
"tieBreak": [[{
"_id": ObjectId("5ac61f8002e836a14c4ab2b1"),
"name": "wins"
},
{
"_id": ObjectId("5ac61f8002e836a14c4ab2b0"),
"name": "balance"
}]]
This means that this function added a List of TieBreaks inside one tieBreak document, but my intention is to add a list of TieBreaks and each value of that list fill just one document, the return should me like this:
"tieBreak": [{
"_id": ObjectId("5ac61f8002e836a14c4ab2b1"),
"name": "wins"
},
{
"_id": ObjectId("5ac61f8002e836a14c4ab2b0"),
"name": "balance"
}]
How can I do it?
Thank you