-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3755 Provide an index creation helper #1303
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
adc4ee0
format mongoc-collection.c
kevinAlbs f60b9a7
add `mongoc_collection_create_indexes_with_opts`
kevinAlbs 40895b1
make `assert_match_bson` a macro
kevinAlbs b135364
fixup `hex_to_bin` helper
kevinAlbs a353aff
update legacy test runner to use `mongoc_collection_create_indexes_wi…
kevinAlbs 9f56e41
use `mongoc_collection_create_indexes_with_opts` in `create_collectio…
kevinAlbs 7dde06e
use `mongoc_collection_create_indexes_with_opts` in `operation_create…
kevinAlbs 2b0e832
fix placement of `strlen`
kevinAlbs 2c12872
use `mongoc_collection_create_indexes_with_opts` in examples
kevinAlbs 4adccf9
add documentation page for `mongoc_collection_create_indexes_with_opts`
kevinAlbs cc16bf6
update "Creating Indexes" guide
kevinAlbs 8776adf
add file name to example error message
kevinAlbs 56af5fb
fix documented type of `models` to include `*`
kevinAlbs ad341ac
simplify error handling
kevinAlbs 04b8b6b
revise assert message
kevinAlbs 989af2c
use `mongoc_collection_create_indexes_with_opts` in more tests
kevinAlbs 9418afd
rename FAIL to HANDLE_ERROR
kevinAlbs e745334
document "success" and "failure" paths in example
kevinAlbs fbee4aa
rename guide page to "Manage Collection Indexes"
kevinAlbs 7d42707
rename guide file to `manage-collection-indexes.rst`
kevinAlbs 4b7658f
rename `example-create-indexes.c` to `example-manage-collection-index…
kevinAlbs 5d80add
add "See Also" sections
kevinAlbs 43fcf88
link to `createIndexes` documentation for form of `keys`
kevinAlbs 7ccd4be
document `mongoc_index_model_t`
kevinAlbs e561997
change `BSON_ASSERT` to `return NULL;`
kevinAlbs c447031
make pointer argument const
kevinAlbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
:man_page: mongoc_manage_collection_indexes | ||
|
||
Manage Collection Indexes | ||
========================= | ||
|
||
To create indexes on a MongoDB collection, use :symbol:`mongoc_collection_create_indexes_with_opts`: | ||
|
||
.. literalinclude:: ../examples/example-manage-collection-indexes.c | ||
:language: c | ||
:start-after: // Create an index ... begin | ||
:end-before: // Create an index ... end | ||
:dedent: 6 | ||
|
||
To list indexes, use :symbol:`mongoc_collection_find_indexes_with_opts`: | ||
|
||
.. literalinclude:: ../examples/example-manage-collection-indexes.c | ||
:language: c | ||
:start-after: // List indexes ... begin | ||
:end-before: // List indexes ... end | ||
:dedent: 6 | ||
|
||
To drop an index, use :symbol:`mongoc_collection_drop_index_with_opts`. The index name may be obtained from the ``keys`` document with :symbol:`mongoc_collection_keys_to_index_string`: | ||
|
||
.. literalinclude:: ../examples/example-manage-collection-indexes.c | ||
:language: c | ||
:start-after: // Drop an index ... begin | ||
:end-before: // Drop an index ... end | ||
:dedent: 6 | ||
|
||
For a full example, see `example-manage-collection-indexes.c <https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/examples/example-manage-collection-indexes.c>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/libmongoc/doc/mongoc_collection_create_indexes_with_opts.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
:man_page: mongoc_collection_create_indexes_with_opts | ||
|
||
mongoc_collection_create_indexes_with_opts() | ||
============================================ | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
typedef struct _mongoc_index_model_t mongoc_index_model_t; | ||
|
||
mongoc_index_model_t * | ||
mongoc_index_model_new (const bson_t *keys, const bson_t *opts); | ||
|
||
void mongoc_index_model_destroy (mongoc_index_model_t *model); | ||
|
||
bool | ||
mongoc_collection_create_indexes_with_opts (mongoc_collection_t *collection, | ||
mongoc_index_model_t **models, | ||
size_t n_models, | ||
const bson_t *opts, | ||
bson_t *reply, | ||
bson_error_t *error); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``collection``: A :symbol:`mongoc_collection_t`. | ||
* ``models``: An array of ``mongoc_index_model_t *``. | ||
* ``n_models``: The number of ``models``. | ||
* ``opts``: Optional options. | ||
* ``reply``: An optional location for the server reply to the ``createIndexes`` command. | ||
* ``error``: An optional location for a :symbol:`bson_error_t <errors>` or ``NULL``. | ||
|
||
.. |opts-source| replace:: ``collection`` | ||
|
||
.. include:: includes/write-opts.txt | ||
|
||
Additional options passed in ``opts`` are appended to the ``createIndexes`` command. See the `MongoDB Manual for createIndexes <https://www.mongodb.com/docs/manual/reference/command/createIndexes/>`_ for all supported options. | ||
|
||
If no write concern is provided in ``opts``, the collection's write concern is used. | ||
|
||
mongoc_index_model_t | ||
```````````````````` | ||
Each ``mongoc_index_model_t`` represents an index to create. ``mongoc_index_model_new`` includes: | ||
|
||
* ``keys`` Expected to match the form of the ``key`` field in the `createIndexes <https://www.mongodb.com/docs/manual/reference/command/createIndexes/>`_ command. | ||
* ``opts`` Optional index options appended as a sibling to the ``key`` field in the `createIndexes <https://www.mongodb.com/docs/manual/reference/command/createIndexes/>`_ command. | ||
|
||
|
||
Description | ||
----------- | ||
|
||
This function wraps around the `createIndexes <https://www.mongodb.com/docs/manual/reference/command/createIndexes/>`_ command. | ||
|
||
Errors | ||
------ | ||
|
||
Errors are propagated via the ``error`` parameter. | ||
|
||
Returns | ||
------- | ||
|
||
Returns ``true`` if successful. Returns ``false`` and sets ``error`` if there are invalid arguments or a server or network error. | ||
|
||
.. seealso:: | ||
|
||
| :doc:`manage-collection-indexes`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.