Hello. I’m still new to the nuances of Mongo and have the following issue. I’m working on a .Net project using MongoDB.Driver 2.13.0. I have the following document structure.
I have an “lrec80” array with one or more elements that contain a “RR4NFAD” DBRef to a document in another collection.
{
"lrec80" : [
{
"RR4NFAD" : {
"$ref" : "RR4OCO",
"$id" : ObjectId("0000000000000000879866fe"),
"$db" : "tpfdf"
},
"RR4NCTY" : "LAX",
"RR4NNBR" : 1
},
{
"RR4NFAD" : {
"$ref" : "RR4OCO",
"$id" : ObjectId("0000000000000000879866fe"),
"$db" : "tpfdf"
},
"RR4NCTY" : "MSY",
"RR4NNBR" : 1
},
],
"_id" : ObjectId("0000000000000000ec013401")
}
I can easily delete the referenced document in the other collection, but how do I perform a batch delete of elements in the array that all have the same ObjectID of the document in the other collection?
I’ve tried the following without success to filter out the elements from the array for deletion
var mgdbref = new MongoDBRef(_appConfiguration.MongoDbConnection["MongoDatabaseName"],
"RR4OCO", "0000000000000000ec013401");
var embeddedDoc = new BsonDocument
{
/*{ "$ref", "RR4OCO"},*/
{ "$id", new ObjectId(objectId) }
};
var deleteDoc = new BsonDocument
{
{ "RR4NFAD", embeddedDoc (or mgdbref) }
};
I’m probably missing something simple, but I can’t figure it out. Thanks for any help you can offer!