diff --git a/source/core/sharding-internals.txt b/source/core/sharding-internals.txt index 5d93486f127..a76bdcf7c99 100644 --- a/source/core/sharding-internals.txt +++ b/source/core/sharding-internals.txt @@ -511,6 +511,27 @@ member has replicated changes before allowing new chunk migrations. .. _config-database: .. _sharding-internals-config-database: +Determine if You are Connected to a :program:`mongos` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If your application must determine whether it is connected to a +:program:`mongos`, use the :dbcommand:`isMaster` command. If the +application is connected to a :program:`mongos`, the :dbcommand:`isMaster` +command returns a document with the string ``isdbgrid`` in the ``msg`` +field. For example: + +.. code-block:: javascript + + { + "ismaster" : true, + "msg" : "isdbgrid", + "maxBsonObjectSize" : 16777216, + "ok" : 1 + } + +If the application is instead connected to a :program:`mongod`, the +returned document does not include the ``isdbgrid`` string. + Config Database --------------- diff --git a/source/reference/command/isdbGrid.txt b/source/reference/command/isdbGrid.txt index 07e39bda3f4..aa8afb8f019 100644 --- a/source/reference/command/isdbGrid.txt +++ b/source/reference/command/isdbGrid.txt @@ -1,26 +1,41 @@ ======== -isdbGrid +isdbgrid ======== .. default-domain:: mongodb -.. dbcommand:: isdbGrid +.. dbcommand:: isdbgrid - Use this command to determine if the process is a :program:`mongos` - or a :program:`mongod`. Consider the following command prototype: + This command verifies that a process is a :program:`mongos`. + + If you issue the :dbcommand:`isdbgrid` command when connected to a + :program:`mongos`, the response document includes the ``isdbgrid`` + field set to ``1``. The returned document is similar to the + following: .. code-block:: javascript - { isdbGrid: 1 } + { "isdbgrid" : 1, "hostname" : "app.example.net", "ok" : 1 } - If connected to a :program:`mongos`, the response document - resembles the following: + If you issue the :dbcommand:`isdbgrid` command when connected to a + :program:`mongod`, MongoDB returns an error document. The + :dbcommand:`isdbgrid` command is not available to :program:`mongod`. + The error document, however, also includes a line that reads + ``"isdbgrid" : 1``, just as in the document returned for a + :program:`mongos`. The error document is similar to the following: .. code-block:: javascript - { "isdbgrid" : 1, "hostname" : "app.example.net", "ok" : 1 } - - You can also use the :dbcommand:`isMaster` command, which when - connected to a :program:`mongos`, contains the string - ``isdbgrid`` in the ``msg`` field of its output document. + { + "errmsg" : "no such cmd: isdbgrid", + "bad cmd" : { + "isdbgrid" : 1 + }, + "ok" : 0 + } + + You can instead use the :dbcommand:`isMaster` command to determine + connection to a :program:`mongos`. When connected to a + :program:`mongos`, the :dbcommand:`isMaster` command returns a document that + contains the string ``isdbgrid`` in the ``msg`` field.