[SERVER-34320] Embedded service does not support creating indexes Created: 04/Apr/18  Updated: 29/Oct/23  Resolved: 06/Apr/18

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 3.7.4

Type: Task Priority: Major - P3
Reporter: Adam Chelminski (Inactive) Assignee: Henrik Edin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Platforms 2018-04-09
Participants:

 Description   

When using the Java driver to create an index on an embedded MongoDB cluster with the following code:

MongoClient mongoClient = /* code to get the client */;
MongoCollection items = mongoClient.getDatabase("todo").getCollection("items");
items.createIndex(Indexes.ascending("task"));

I get the following exception:

com.mongodb.MongoCommandException: Command failed with error 238: 'Not implemented for embedded: operator()' on server 127.0.0.1:27017. The full response is { "ok" : 0.0, "errmsg" : "Not implemented for embedded: operator()", "code" : 238, "codeName" : "NotImplemented" }

I'm able to replicate the error using the following runCommand

MongoDatabase todoDB = mongoClient.getDatabase("todo");
todoDB.runCommand(new Document()
            .append("createIndexes", "items")
            .append("indexes", Arrays.asList(new Document()
                .append("key", new Document()
                    .append("task", 1))
                .append("name", "task_1"))
            ));

Equivalent to

db.runCommand(
  {
    createIndexes: "items",
    indexes: [
        {
            key: {
                "task": 1,
            },
            name: "task_1"
        }
    ]
  }
)

It seems to be an issue with the creation of any index, and I suspect it's hitting this line of code, but I haven't confirmed this: https://github.com/mongodb/mongo/blob/master/src/mongo/client/embedded/replication_coordinator_embedded.cpp#L331

If it would help, here's the full stacktrace:

Caused by: com.mongodb.MongoCommandException: Command failed with error 238: 'Not implemented for embedded: operator()' on server 127.0.0.1:27017. The full response is { "ok" : 0.0, "errmsg" : "Not implemented for embedded: operator()", "code" : 238, "codeName" : "NotImplemented" }
                                                                      at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
                                                                      at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:293)
                                                                      at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:254)
                                                                      at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72)
                                                                      at com.mongodb.embedded.client.EmbeddedServer$DefaultServerProtocolExecutor.execute(EmbeddedServer.java:141)
                                                                      at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269)
                                                                      at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131)
                                                                      at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123)
                                                                      at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:226)
                                                                      at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:217)
                                                                      at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:154)
                                                                      at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:147)
                                                                      at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:174)
                                                                      at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:169)
                                                                      at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:462)
                                                                      at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:424)
                                                                      at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:169)
                                                                      at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:70)
                                                                      at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:151)
                                                                      at com.mongodb.client.internal.MongoCollectionImpl.executeCreateIndexes(MongoCollectionImpl.java:739)
                                                                      at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:722)
                                                                      at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:717)
                                                                      at com.mongodb.client.internal.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:702)
                                                                      at com.mongodb.client.internal.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:697)
                                                                      at com.mongodb.todo.TodoListActivity.onCreate(TodoListActivity.java:47)



 Comments   
Comment by Githook User [ 06/Apr/18 ]

Author:

{'email': 'henrik.edin@mongodb.com', 'name': 'Henrik Edin', 'username': 'henrikedin'}

Message: SERVER-34320 Fix index building in embedded.
Branch: master
https://github.com/mongodb/mongo/commit/1c0c35ba16ab6f03902db70f9e5750a74877e8a4

Generated at Thu Feb 08 04:36:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.