Getting the following error while updating an array of objects with $ref field.
The DBRef $ref field must be followed by a $id field
Using the following query:
shopCollection.updateOne({_id:ObjectId("601c12ae89e49906305488b5")},
{$push:{products:{$ref: "products",$id: ObjectId("601c0a532da6b110a06d4b0a")}}},function(err,result){
if(err){
console.log(err);
}
})
products array validation schema:
products:{
bsonType:"array",
items:{
bsonType:"object",
properties:{
$ref:{
bsonType:"products",
description: "required"
},
$id:ObjectId
}
}
}