Skip to content

DOCSP-1540 - Integrating Compass into indexes page #3189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added source/images/compass-create-index-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/compass-index-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/compass-index-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
312 changes: 312 additions & 0 deletions source/includes/driver-example-indexes-1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
To create an index in the
:doc:`Mongo Shell </getting-started/shell/client/>`, use
:method:`db.collection.createIndex()`.

.. class:: copyable-code
.. code-block:: javascript

db.collection.createIndex( <key and index type specification>, <options> )

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: javascript

db.collection.createIndex( { name: -1 } )

The :method:`db.collection.createIndex` method only
creates an index if an index of the same specification does
not already exist.

- id: compass
content: |
.. important::

To create an index on a collection in |compass|,
the collection must contain documents.

To create an index in
:ref:`MongoDB Compass <compass-index>`, complete the following
steps:

1. Navigate to the collection for which you wish to create
the index:

a. In the left-hand MongoDB Compass navigation pane, click
the database to which your target collection belongs.

b. From the database view, click the target collection name.

#. Click the :guilabel:`Indexes` tab:

.. figure:: /images/compass-index-tab.png
:alt: Compass index tab

.. raw:: html

<br>

#. Click the :guilabel:`Create Index` button:

.. figure:: /images/compass-create-index-button.png
:alt: Compass index button

.. raw:: html

<br>

The following dialog appears:

.. figure:: /images/compass-index-dialog.png
:scale: 60 %
:alt: Compass index dialog

#. (Optional) Enter the index name.

Leaving this field blank causes |compass| to create a
default name for the index.

#. Add fields to the index.

Use the :guilabel:`Configure the index definition` section
of the dialog to define the fields for your index and
their respective types. To create an index on multiple
fields, click :guilabel:`Add another field`.

#. (Optional) Specify the index options.

The following index options can be specified:

- Build index in the background
- Create a :ref:`unique index <unique-index>`
- Create :ref:`TTL <ttl-index>`
- Partial :ref:`filter expression <partial-index>`

#. Click :guilabel:`Create` to create the index.

- id: python
content: |
To create an index using the
`Python driver <https://api.mongodb.com/python/current/>`_,
use :py:meth:`pymongo.collection.Collection.create_index`.

.. class:: copyable-code
.. code-block:: python

db.collection.create_index([(<key and index type specification>)], <options> )

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: python

collection.create_index([("name", pymongo.DESCENDING)])

The :py:meth:`pymongo.collection.Collection.create_index`
method only creates an index if an index of the same
specification does not already exist.

- id: java-sync
content: |
To create an index using the
`Java driver <https://mongodb.github.io/mongo-java-driver/>`_,
use
`com.mongodb.client.MongoCollection.createIndex <http://mongodb.github.io/mongo-java-driver/3.4/javadoc/?com/mongodb/client/MongoCollection.html#createIndex-org.bson.conversions.Bson->`_.

.. class:: copyable-code
.. code-block:: java

collection.createIndex( <key and index type specification>, <options> )

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: java

collection.createIndex(Indexes.descending("name"));

The `com.mongodb.client.MongoCollection.createIndex <http://mongodb.github.io/mongo-java-driver/3.4/javadoc/?com/mongodb/client/MongoCollection.html#createIndex-org.bson.conversions.Bson->`_.
method only creates an index if an index of the same
specification does not already exist.

- id: java-async
content: |
To create an index using the
`Async Java driver <http://mongodb.github.io/mongo-java-driver/3.0/driver-async/>`_,
use
`com.mongodb.async.client.MongoCollection.createIndex <http://mongodb.github.io/mongo-java-driver/3.4/javadoc/?com/mongodb/async/client/MongoCollection.html#createIndex-org.bson.conversions.Bson-com.mongodb.async.SingleResultCallback->`_.

.. class:: copyable-code
.. code-block:: java

collection.createIndex( <key and index type specification>, <options>, <callbackFunction>)

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: java

collection.createIndex(Indexes.descending("name"), someCallbackFunction());

The `com.mongodb.async.client.MongoCollection.createIndex <http://mongodb.github.io/mongo-java-driver/3.4/javadoc/?com/mongodb/async/client/MongoCollection.html#createIndex-org.bson.conversions.Bson-com.mongodb.async.SingleResultCallback->`_
method only creates an index if an index of the same
specification does not already exist.

- id: nodejs
content: |
To create an index using the
`Node.JS driver <https://mongodb.github.io/node-mongodb-native/>`_,
use
`createIndex() <http://mongodb.github.io/node-mongodb-native/2.1/tutorials/create-indexes/>`_.

.. class:: copyable-code
.. code-block:: javascript

collection.createIndex( { <key and index type specification> }, function(err, result) {
console.log(result);
callback(result);
}

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: javascript

collection.createIndex( { name : -1 }, function(err, result) {
console.log(result);
callback(result);
}

The `createIndex() <http://mongodb.github.io/node-mongodb-native/2.1/tutorials/create-indexes/>`_
method only creates an index if an index of the same
specification does not already exist.

- id: php
content: |
To create an index using the
`PHP driver <http://php.net/manual/en/set.mongodb.php>`_, use
`MongoCollection::createIndex() <http://php.net/manual/en/mongocollection.createindex.php>`_.

.. class:: copyable-code
.. code-block:: php

$collection->createIndex(array(<key and index type specification>), array(<options>));

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: php

$collection->createIndex(array('name' => -1));

The `MongoCollection::createIndex() <http://php.net/manual/en/mongocollection.createindex.php>`_
method only creates an index if an index of the same
specification does not already exist.

- id: perl
content: |
To create an index using the
`Perl driver <http://search.cpan.org/dist/MongoDB/lib/MongoDB.pm>`_,
use
`create_one() <https://metacpan.org/pod/MongoDB::Examples#CREATE-INDEX-myindexname-ON-users(name)>`_.

.. class:: copyable-code
.. code-block:: perl

my $indexes = $db->get_collection( <collection> )->indexes;
$indexes->create_one( [ <key and index type specification> ] );

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: perl

my $indexes = $db->get_collection( <collection> )->indexes;
$indexes->create_one( [ name => -1 ] );

The `create_one() <https://metacpan.org/pod/MongoDB::Examples#CREATE-INDEX-myindexname-ON-users(name)>`_
method only creates an index if an index of the same
specification does not already exist.

- id: ruby
content: |
To create an index using the
`Ruby driver <https://api.mongodb.com/ruby/current/>`_, use
`Mongo::Index::View#create_one <http://www.rubydoc.info/github/mongodb/mongo-ruby-driver/Mongo%2FIndex%2FView%3Acreate_one>`_.

.. class:: copyable-code
.. code-block:: ruby

client[:collection].indexes.create_one({ <key and index type specification> }, {options})

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: ruby

client[:collection].indexes.create_one({ name: -1 })

The `Mongo::Index::View#create_one <http://www.rubydoc.info/github/mongodb/mongo-ruby-driver/Mongo%2FIndex%2FView%3Acreate_one>`_
method only creates an index if an index of the same
specification does not already exist.

- id: scala
content: |
To create an index using the
`Scala driver <http://mongodb.github.io/mongo-scala-driver/>`_,
use
`org.mongodb.scala.model.Indexes <https://mongodb.github.io/mongo-scala-driver/1.0/scaladoc/index.html#org.mongodb.scala.model.Indexes$>`_.

.. class:: copyable-code
.. code-block:: scala

collection.createIndex(<key and index type specification>)

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: scala

collection.createIndex(descending("name"))

The `org.mongodb.scala.model.Indexes <https://mongodb.github.io/mongo-scala-driver/1.0/scaladoc/index.html#org.mongodb.scala.model.Indexes$>`_
method only creates an index if an index of the same
specification does not already exist.

- id: csharp
content: |
To create an index using the
`.NET driver <http://mongodb.github.io/mongo-csharp-driver/>`_,
use
`MongoCollection.CreateIndex <http://api.mongodb.com/csharp/current/html/Overload_MongoDB_Driver_MongoCollection_CreateIndex.htm>`_.

.. class:: copyable-code
.. code-block:: csharp

collection.CreateIndex( IndexKeys<collection>.<key and index type specification>, <options> );

The following example creates a single key descending index on
the ``name`` field:

.. class:: copyable-code
.. code-block:: csharp

collection.CreateIndex( IndexKeys<collection>.Descending("name") );

The `MongoCollection.CreateIndex <http://api.mongodb.com/csharp/current/html/Overload_MongoDB_Driver_MongoCollection_CreateIndex.htm>`_
method only creates an index if an index of the same
specification does not already exist.
48 changes: 48 additions & 0 deletions source/includes/driver-example-indexes-2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. tabs-drivers::

tabs:

- id: compass
content: |
.. important::

|compass| does not support collation for indexes.

The following examples illustrate indexes and collation in
the :doc:`Mongo Shell </mongo/>`.

- id: python
content: |
.. include:: /includes/fact-collation-driver.rst

- id: java-sync
content: |
.. include:: /includes/fact-collation-driver.rst

- id: java-async
content: |
.. include:: /includes/fact-collation-driver.rst

- id: nodejs
content: |
.. include:: /includes/fact-collation-driver.rst

- id: php
content: |
.. include:: /includes/fact-collation-driver.rst

- id: perl
content: |
.. include:: /includes/fact-collation-driver.rst

- id: ruby
content: |
.. include:: /includes/fact-collation-driver.rst

- id: scala
content: |
.. include:: /includes/fact-collation-driver.rst

- id: csharp
content: |
.. include:: /includes/fact-collation-driver.rst
Loading