「SequoiaDBジャイアントセコイアデータベース」upsert()概要3

エラー

エラー情報はノード診断ログ(diaglog)に記録され、エラーコードを参照できます

コレクションの従業員に2つのレコードがあるとします。

{
  "_id": {
    "$oid": "516a76a1c9565daf06030000"
  },
  "age": 10,
  "name": "Tom"
}
{
  "_id": {
    "$oid": "516a76a1c9565daf06050000"
  },
  "a": 10,
  "age": 21
}

指定された更新ルールに従ってコレクション内のすべてのレコードを更新します。つまり、ルールパラメーターを設定し、condパラメーターとhintパラメーターの内容は設定しません。次の操作は、updateメソッドを使用して設定された従業員のすべてのレコードを更新し、$ inc使用してレコードの年齢フィールドの値を1増やし、nameフィールドの値を「Mike」に変更するのと同じです。 nameフィールドのないレコード、$ set 演算子nameフィールドとその設定値がレコードに挿入され、findメソッドを使用して更新結果を表示できます。

db.sample.employee.upsert( { $inc: { age: 1 }, $set: { name: "Mike" } } )
{
"UpdatedNum": 2,
"ModifiedNum": 2,
"InsertedNum": 0
}
>
db.sample.employee.find()
{
  "_id": {
  "$oid": "516a76a1c9565daf06030000"
  },
  "age": 11,
  "name": "Mike"
}
{
  "_id": {
  "$oid": "516a76a1c9565daf06050000"
  },
  "a": 10,
  "age": 22,
  "name":"Mike"
}
Return 2 row(s).

アクセスプランに従ってレコードを更新します。指定されたインデックス名testIndexがコレクションに存在すると仮定すると、この操作はupdateメソッドを使用するのと同じで、testIndexという名前のインデックスを使用してコレクション内の年齢フィールド値が20より大きいレコードにアクセスします。従業員、およびこれらのレコードの年齢フィールドを変更します。名前に1を追加します。

db.sample.employee.upsert( { $inc: { age: 1 } }, { age: { $gt: 20 } }, { "": "testIndex" } )
{
"UpdatedNum": 1,
"ModifiedNum": 1,
"InsertedNum": 0
}
>
db.sample.employee.find()
{
  "_id": {
  "$oid": "516a76a1c9565daf06050000"
  },
  "a": 10,
  "age": 23,
  "name":"Mike"
}
Return 1 row(s).

パーティションセットsample.employee、パーティションキーは{a:1}で、次のレコードが含まれています

db.sample.employee.find()
{
"_id": {
 "$oid": "5c6f660ce700db6048677154"
},
"a": 1,
"b": 1
}
Return 1 row(s).

KeepShardingKeyパラメーターを指定します。更新ルールのパーティションキーフィールドは保持されません。非パーティションキーbフィールドのみが更新され、パーティションキーaフィールドの値は更新されません。

db.sample.employee.upsert( { $set: { a: 9, b: 9 } }, {}, {}, {}, { KeepShardingKey: false } )
{
"UpdatedNum": 1,
"ModifiedNum": 1,
"InsertedNum": 0
}
>
db.sample.employee.find()
{
"_id": {
 "$oid": "5c6f660ce700db6048677154"
},
"a": 1,
"b": 9
}
Return 1 row(s).

KeepShardingKeyパラメーターを指定します。更新ルールのパーティションキーフィールドを保持します。パーティションキーの更新は現在サポートされていないため、エラーが報告されます。

db.sample.employee.upsert( { $set: { a: 9 } }, {}, {}, {}, { KeepShardingKey: true } )
(nofile):0 uncaught exception: -178
Sharding key cannot be updated

詳細については、Jushanデータベースドキュメントセンタークリックしてください

おすすめ

転載: blog.csdn.net/weixin_45890253/article/details/112984025