$document = $client->$db->$collection->findAndModify(
[ $field => $value ], // query
['$set' => $updatedDocument], // update
null, // only return these fields
[
"sort" => [],
"remove" => false,
"update" => [], // array for update? not sure what this does!
"new" => false,
"upsert" => false
]
);
を削除し、それが条件付きにinsert
、update
またはremove
文書DBに追加のクエリを作成することなく、可能ですか?例えば条件付きで、挿入、更新またはその<a href="http://php.net/manual/en/mongocollection.findandmodify.php" rel="nofollow">syntax for the PHP Driver</a>で文書
:
$document = $client->$db->$collection->findAndModify(
[ $field => $value ], // query
// if $document != $newDocument: update
['$set' => $updatedDocument],
null, // only return these fields
[
"sort" => [],
// if $document != $certainCondition: remove
"remove" => true,
"update" => [],
// if $document does not exist: insert (or upsert?)
"new" => false,
// if $document does not exist: upsert?
"upsert" => false
]
);
'options'はキー配列でなければなりません。 '[" update "=> [...]]' – jszobody
のように@jszobodyああ、訂正しました。 – 3zzy