我想將文檔插入另一個文檔中的數組中Powershell。如何使用PowerShell代碼將文檔添加到MongoDB中的數組?
例如
{
"1" : "A",
"2" : "B",
"3" : [
{
"a" : "AA",
"_id" : ObjectId("5333b74c9e99569836bca41f")
}
],
"_id" : ObjectId("5333b74c9e99569836bca41c")
}
這是我在mongodb shell中的文檔。
{
"1" : "A",
"2" : "B",
"3" : [ ]
"_id" : ObjectId("5333b74c9e99569836bca41c")
}
,這是我在PowerShell代碼:
$embededDocument = new-object Mongodb.Bson.BsonDocument
$embededDocument.Add("a", "AA")
$embededDocument.Add("B2", "2")
$embededDocument.Add("C2", "3")
$parentDocument["3"].Add($embededDocument)
這不是作爲數組工作爲空運行的代碼後,我嘗試使用添加,插入,並用同樣的結果推...
任何想法我做錯了什麼?
非常感謝你
解決了我的問題+1 – Disposer