I would like to insert a document into an array within another document in Powershell.
e.g.
{
"1" : "A",
"2" : "B",
"3" : [
{
"a" : "AA",
"_id" : ObjectId("5333b74c9e99569836bca41f")
}
],
"_id" : ObjectId("5333b74c9e99569836bca41c")
}
this is my document in mongodb shell.
{
"1" : "A",
"2" : "B",
"3" : [ ]
"_id" : ObjectId("5333b74c9e99569836bca41c")
}
and this is my code in powershell:
$embededDocument = new-object Mongodb.Bson.BsonDocument
$embededDocument.Add("a", "AA")
$embededDocument.Add("B2", "2")
$embededDocument.Add("C2", "3")
$parentDocument["3"].Add($embededDocument)
this is not working as the array is empty after run the code, I tried using Add, Insert and Push with same result...
Any idea what I'm doing wrong?
thank you very much