我是mongoDB中的新成員,所以我需要一些幫助。
我有一個備份集合。它包含以下數據文件:在不刪除的情況下更新MongoDB集合中的某些文檔
{
"_id" : ObjectId("59f18942e7798954dc373b67"),
"category" : "building",
},
{
"_id" : ObjectId("59f18942e7798954dc373b68"),
"category" : "building",
},
{
"_id" : ObjectId("59f18942e7798954dc373b69"),
"category" : "tree",
"type" : 18,
},
{
"_id" : ObjectId("59f18942e7798954dc373b70"),
"category" : "book",
"type" : 18,
}
然後,例如,某些對象發生了變化,成爲這樣的:
{
"_id" : ObjectId("59f18942e7798954dc373b67"),
"category" : "building",
"size" : 100
},
{
"_id" : ObjectId("59f18942e7798954dc373b68"),
"category" : "building",
"size" : 400
},
{
"_id" : ObjectId("59f18942e7798954dc373b70"),
"category" : "book",
"type" : 18,
"title" : "New"
}
所以我需要在我的數據庫更新它們。正如我所理解的那樣,請替換。我已閱讀關於使用'upsert'和'multi'的文檔。但我無法實現它。
如何做到這一點?
向我們展示你已經嘗試了什麼,發生了什麼和在那裏你就完蛋了。 –
此外,請查看文檔:https://docs.mongodb.com/php-library/current/tutorial/crud/#update-one-document –
我已閱讀此文檔。但是,據我所知,我只能替換一個文件,但不是我需要的全部文件(例如,一個查詢中有3個文件)。我對嗎? –