diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-12-02 10:06:21 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-12-02 10:06:21 +0100 |
commit | fd841e416881cc0392e61ec312c1870f3a0004bd (patch) | |
tree | 8357ba56e79d614ba57f722e7878b853591dc339 /docs/tutorial/tut_mongo_sync_cmd_index_create.h |
Initial import of libmongo-client version 0.1.8-2
Diffstat (limited to 'docs/tutorial/tut_mongo_sync_cmd_index_create.h')
-rw-r--r-- | docs/tutorial/tut_mongo_sync_cmd_index_create.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/docs/tutorial/tut_mongo_sync_cmd_index_create.h b/docs/tutorial/tut_mongo_sync_cmd_index_create.h new file mode 100644 index 0000000..22842e0 --- /dev/null +++ b/docs/tutorial/tut_mongo_sync_cmd_index_create.h @@ -0,0 +1,66 @@ +/** @page tut_mongo_sync_cmd_index_create Creating indexes + * + * This example will show how to properly create indexes, how to + * verify its success, and will also give hints on how to prepare the + * BSON used to create the index. + * + * @dontinclude tut_mongo_sync_cmd_index_create.c + * @until stdio.h + * + * We will be creating and verifying multiple indexes, so lets create + * a function that takes a connection, a prepared index, and does the + * create and verify magic. + * + * @line static void + * @until } + * @until } + * + * This will create the index, and if it succeeds, write that to + * stdout. If it fails, it will try to query the last error, and print + * that to stderr. + * + * All we have to do past this point, is to build a few index + * specifications in BSON, and see what happens: + * + * @line int + * @until bson + * + * @line invalid + * @until bson_finish + * + * The first index spec we create will have a single index field, @a + * name, where we set the value to an empty string. However - as we + * will soon see - this is not a valid specification, as MongoDB does + * not accept string-typed fields in the index spec. + * + * @line index + * @until bson_finish + * + * Armed with the knowledge that strings are not going to work, we + * turn to our trusty old integers. Integers (32-bit integers at that, + * there really is no need to use a 64-bit value here) are the best + * fit for the type of an index field, because one can tell MongoDB + * the sort order (with negative or positive numbers) with them easily. + * + * @line conn = + * @until } + * + * We now have two index specs in BSON, and an established connection, + * lets see what happens! + * + * @line create_and_verify + * @until conn, index + * + * The first will - as explained above - fail, the second will + * succeed. + * + * And that is all it takes to create simple indexes! We now free up + * our BSON objects and disconnect, and the tutorial program is all + * done and finished. + * + * @line bson_free + * @until disconnect + * + * @line return + * @until } + */ |