I've been trying to remove the final element of an array in a MongoID document, but I am struggling for some unknown reason.
We have a document in MongoDB:
{
"_id" : ObjectId("606c774ff34c295ec7ac5eb7"),
"child_table" : [
{
"_id" : ObjectId("606c7768f34c291171ac5ec2"),
"string3" : "y"
},
{
"_id" : ObjectId("606c7768f34c291171ac5ef6"),
"string3" : "u"
}
]
}
This document is contained within record
.
record = Record.find_by(:id=> "606c774ff34c295ec7ac5eb7")
I can delete the second element, which I'm doing with:
record.child_table.delete_at(record.child_table.count-1)
This works fine, the second element of the array child_table
is deleted. All right.
However, when I go to delete the final element in the array, the code runs with no errors, but I go to check the document in Mongo and it is still showing the final element.
I have also tried running:
self.unset(:child_table)
But this has not done anything for me.
Please let me know any suggestions! Thanks