Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,11 @@ internal class JavaServiceProvider(private val client: MongoClient,
}

@HostAccess.Export
override fun createIndexes(database: String, collection: String, indexSpecs: Value?): Value = promise<Any?> {
override fun createIndexes(database: String, collection: String, indexSpecs: Value?, options: Value?, dbOptions: Value?): Value = promise<Any?> {
val indexSpecs = toList(indexSpecs, "indexSpecs") ?: emptyList()
val dbOptions = toDocument(dbOptions, "dbOptions")
if (indexSpecs.any { it !is Document }) throw IllegalArgumentException("Index specs must be a list of documents. Got $indexSpecs")
getDatabase(database, null).flatMap { db ->
getDatabase(database, dbOptions).flatMap { db ->
val convertedIndexes = indexSpecs.map { spec ->
convert(IndexModel(Document()), indexModelConverters, indexModelDefaultConverter, spec as Document)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal interface WritableServiceProvider {
fun save(database: String, collection: String, document: Value, options: Value?, dbOptions: Value?): Value
fun remove(database: String, collection: String, query: Value, options: Value?, dbOptions: Value?): Value
fun convertToCapped(database: String, collection: String, size: Number, options: Value?): Value
fun createIndexes(database: String, collection: String, indexSpecs: Value?): Value
fun createIndexes(database: String, collection: String, indexSpecs: Value?, options: Value?, dbOptions: Value?): Value
fun dropIndexes(database: String, collection: String, indexes: Value?, options: Value?): Value
fun reIndex(database: String, collection: String, options: Value?, dbOptions: Value?): Value
fun dropCollection(database: String, collection: String, options: Value?): Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CollectionTest : ShellTestCase() {
@Test fun testCountWithQuery() = test()
@Test fun testCountWithUnknownOption() = test()
@Test fun testCreateIndex() = test()
@Test fun testCreateIndexes() = test()
@Test fun testDeleteMany() = test()
@Test fun testDeleteOne() = test()
@Test fun testDistinct() = test()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[ "category_1" ]
[ { "v": 2, "key": { "_id": 1 }, "name": "_id_", "ns": "admin.coll" }, { "v": 2, "key": { "category": 1 }, "name": "category_1", "ns": "admin.coll", "collation": { "locale": "fr", "caseLevel": false, "caseFirst": "off", "strength": 3, "numericOrdering": false, "alternate": "non-ignorable", "maxVariable": "punct", "normalization": false, "backwards": false, "version": "57.1" } } ]
"category_1"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ db.coll.insertOne({category: "cat2", v: 2});
db.coll.insertOne({category: "cat2", v: 3});
// command
db.coll.createIndex({category: 1}, {collation: {locale: "fr"}});
// command
// command getArrayItem=1 extractProperty=name
db.coll.getIndexes();
// clear
db.coll.drop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ "category_1", "title_1" ]
"category_1"
"title_1"
11 changes: 11 additions & 0 deletions packages/java-shell/src/test/resources/collection/createIndexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// before
db.coll.deleteMany({});
db.coll.insertMany([{category: "cat1", v: 1}, {category: "cat2", title: "t3", v: 2}, {category: "cat2", title: "t4", v: 3}]);
// command
db.coll.createIndexes([{"category": 1}, {"title": 1}], {collation: {locale: "fr", strength: 2}});
// command getArrayItem=1 extractProperty=name
db.coll.getIndexes();
// command getArrayItem=2 extractProperty=name
db.coll.getIndexes();
// clear
db.coll.drop();
2 changes: 1 addition & 1 deletion packages/shell-api/src/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ describe('Collection', () => {
let internalSession: StubbedInstance<ServiceProviderSession>;
const exceptions = {
renameCollection: { a: ['name'] },
createIndexes: { a: [[]] },
createIndexes: { a: [[]], i: 4 },
runCommand: { a: ['coll', {} ], m: 'runCommandWithCheck', i: 2 },
findOne: { m: 'find' },
insert: { m: 'insertMany' },
Expand Down
6 changes: 3 additions & 3 deletions packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ export default class Collection extends ShellApiClass {

this._emitCollectionApiCall('createIndexes', { specs });

return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, specs, this._database._baseOptions);
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, specs, {}, this._database._baseOptions);
}

/**
Expand All @@ -999,7 +999,7 @@ export default class Collection extends ShellApiClass {
this._emitCollectionApiCall('createIndex', { keys, options });

const spec = { ...this._database._baseOptions, ...options, key: keys };
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, [spec]);
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, [spec], {}, this._database._baseOptions);
}

/**
Expand All @@ -1025,7 +1025,7 @@ export default class Collection extends ShellApiClass {
this._emitCollectionApiCall('ensureIndex', { keys, options });

const spec = { ...this._database._baseOptions, ...options, key: keys };
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, [spec]);
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, [spec], {}, this._database._baseOptions);
}

/**
Expand Down