Docs Menu
Docs Home
/
MongoDB マニュアル
/ / /

cursor.comment()

項目一覧

  • 定義
  • 動作
  • 出力例
cursor.comment()

重要

mongosh メソッド

これは mongoshメソッドです。 これは、 Node.jsまたはその他のプログラミング言語固有のドライバー メソッドのドキュメントではありません

ほとんどの場合、 mongoshメソッドはレガシーの mongo shell メソッドと同じように動作します。 ただし、一部のレガシー メソッドはmongoshでは利用できません。

レガシーmongo shell のドキュメントについては、対応する MongoDB Server リリースのドキュメントを参照してください。

MongoDB API ドライバーについては、各言語のMongoDB ドライバードキュメント を参照してください。

バージョン 3.2 で追加

クエリにcommentフィールドを追加します。

cursor.comment() の構文は次のとおりです。

cursor.comment( <string> )

comment() には、次のパラメーターがあります。

Parameter
タイプ
説明
comment
string
クエリに適用するコメント。

comment() は、コメントstringを検索操作に関連付けます。 これにより、次の診断出力で特定のクエリを追跡しやすくなります。

ログ、 データベースプロファイラー mongodチュートリアル 、または コマンドのdb.currentOp() ログの冗長度の構成 を参照してください。

次の操作では、 restaurantsコレクションのクエリにコメントを添付します。

db.restaurants.find(
{ "borough" : "Manhattan" }
).comment( "Find all Manhattan restaurants" )

以下は、 system.profileからの引用です。

{
"op" : "query",
"ns" : "guidebook.restaurant",
"query" : {
"find" : "restaurant",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants"
},
...
}

以下は、 mongodログからの抜粋です。 読みやすくするためにフォーマットされています。

重要

QUERYの冗長レベルは0より大きくなければなりません。 「ログの冗長レベルの構成 」を参照してください

2015-11-23T13:09:16.202-05:00 I COMMAND [conn1]
command guidebook.restaurant command: find {
find: "restaurant",
filter: { "borough" : "Manhattan" },
comment: "Find all Manhattan restaurants"
}
...

たとえば、 mongodインスタンスで次の操作が現在実行されているとします。

db.restaurants.find(
{ "borough" : "Manhattan" }
).comment("Find all Manhattan restaurants")

db.currentOp()コマンドを実行すると、次の結果が返されます。

{
"inprog" : [
{
"host" : "198.51.100.1:27017",
"desc" : "conn3",
"connectionId" : 3,
...
"op" : "query",
"ns" : "test.$cmd",
"command" : {
"find" : "restaurants",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants",
"$db" : "test"
},
"numYields" : 0,
...
}
],
"ok" : 1
}

戻る

cursor.collation