you can use a mixing scheme
{
"_id": ""5a2539b41c574006c46f1a07",
"name": "xyz",
"ingredients": mongoose.Schema.Types.mix
}
link way to create dynamic document keys in mongodb
Dynamic key insertion is so easy
insertData_dynamic_colone: function(collection, colone1, colone2) {
var obj = {};
obj[colone1] = "14";
obj[colone2] = "15";
dbObject.collection(collection).insertOne(obj, function(err, result) {
assert.equal(err, null);
});
}
I know that you will also need to update the dymanic key in the future to take the link Update the Mongo array: delete the dynamic key
collection.update(
{"_id": ObjectId("5a2539b41c574006c46f1a07")},
{"$unset": {"ingredients.5a23f5e6159f5c3438c75971": ""}}
)
source
share