Skip to content

Commit 191b030

Browse files
committed
add shim create_index implementation
1 parent 4441d20 commit 191b030

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/mongocxx/collection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,22 @@ std::int64_t collection::count(bsoncxx::document::view filter, const options::co
402402
return result;
403403
}
404404

405+
bsoncxx::document::value collection::create_index(bsoncxx::document::view keys, bsoncxx::document::view options) {
406+
scoped_bson_t bson_keys{keys};
407+
bson_error_t error;
408+
409+
auto result = libmongoc::collection_create_index(_impl->collection_t, bson_keys.bson(),
410+
nullptr, &error);
411+
412+
if (!result) {
413+
// TODO: throw an exception here
414+
}
415+
416+
// TODO: return the response from the server, this is not possible now due to the way
417+
// libmongoc works.
418+
return bsoncxx::document::value{bsoncxx::document::view{}};
419+
}
420+
405421
void collection::drop() {
406422
bson_error_t error;
407423

src/mongocxx/collection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class LIBMONGOCXX_API collection {
199199
/// @param options
200200
/// Optional arguments to index creation command, see ensureindex-options link
201201
///
202-
/// @throws operation_exception if the aggregation fails.
202+
/// @throws operation_exception if index creation fails.
203203
///
204204
/// @see http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/
205205
/// @see http://docs.mongodb.org/manual/reference/method/db.collection.ensureIndex/#ensureindex-options

src/mongocxx/private/libmongoc_symbols.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MONGOCXX_LIBMONGOC_SYMBOL(client_get_collection)
3636
MONGOCXX_LIBMONGOC_SYMBOL(client_destroy)
3737
MONGOCXX_LIBMONGOC_SYMBOL(collection_aggregate)
3838
MONGOCXX_LIBMONGOC_SYMBOL(collection_count)
39+
MONGOCXX_LIBMONGOC_SYMBOL(collection_create_index)
3940
MONGOCXX_LIBMONGOC_SYMBOL(collection_destroy)
4041
MONGOCXX_LIBMONGOC_SYMBOL(collection_set_read_prefs)
4142
MONGOCXX_LIBMONGOC_SYMBOL(collection_get_read_prefs)

0 commit comments

Comments
 (0)