# Not able to create indexes using json format on mongodb and unable to generate change logs on existing mongodb databases to capture the changes

**URL:** https://forum.liquibase.org/t/not-able-to-create-indexes-using-json-format-on-mongodb-and-unable-to-generate-change-logs-on-existing-mongodb-databases-to-capture-the-changes/7444
**Category:** General Discussion
**Created:** [October 20, 2022, 12:40pm UTC](https://forum.liquibase.org/t/not-able-to-create-indexes-using-json-format-on-mongodb-and-unable-to-generate-change-logs-on-existing-mongodb-databases-to-capture-the-changes/7444 "2022-10-20T12:40:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kmkrishna1223](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kmkrishna1223](https://forum.liquibase.org/u/kmkrishna1223)
#### Post date: [October 20, 2022, 12:40pm UTC](https://forum.liquibase.org/t/not-able-to-create-indexes-using-json-format-on-mongodb-and-unable-to-generate-change-logs-on-existing-mongodb-databases-to-capture-the-changes/7444/1 "2022-10-20T12:40:20Z")

</div>

Not able to create indexes using json format on mongodb and unable to generate change logs on existing mongodb databases to capture the changes

```auto
{
    "databaseChangeLog": [{
            "property": {
                "name": "collection.name",
                "value": "person3"
            }
        },
        {
            "changeSet": {
                "id": "12334d",
                "author": "murali",
                "changes": [{
                    "createIndex": {
                        "collectionName": "${collection.name}",
                        "indexQuery": { "clientId": 1,"type": 1 },
                        "indexOptions": {
                            "$rawJson": {
                                "unique": true,
                                "name": "new_index_key"
                            }
                        }
                    }
                }]
            }
        }
    ]
}

	... 67 more
Caused by: com.mongodb.MongoCommandException: Command failed with error 67 (CannotCreateIndex): 'Error in specification { key: {} } :: caused by :: Index keys cannot be empty.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Error in specification { key: {} } :: caused by :: Index keys cannot be empty.", "code": 67, "codeName": "CannotCreateIndex"}
	at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:195)
	at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:400)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:324)

```

---

<div class="post-metadata">

### Author: ![tabbyfoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/tabbyfoo/32/748_2.png) [@tabbyfoo](https://forum.liquibase.org/u/tabbyfoo)
#### Post date: [October 26, 2022, 5:42pm UTC](https://forum.liquibase.org/t/not-able-to-create-indexes-using-json-format-on-mongodb-and-unable-to-generate-change-logs-on-existing-mongodb-databases-to-capture-the-changes/7444/2 "2022-10-26T17:42:31Z")

</div>

> [@kmkrishna1223](#):
>
> `Command failed with error 67 (CannotCreateIndex)`

Hi @kmkrishna1223 - Welcome to the Liquibase Community!

I found an issue with a similar error that was related to the size that the index is or might become over time. This one has a lot of discussion on StackOverflow with a couple of suggested answers and comments with helpful information. Have you seen this one already? [indexing - Mongodb - Multiple text index: Index key pattern too large error code 67 - Stack Overflow](https://stackoverflow.com/questions/25336130/mongodb-multiple-text-index-index-key-pattern-too-large-error-code-67)

-Tabby

---

<div class="post-metadata">

### Author: ![kmkrishna1223](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kmkrishna1223](https://forum.liquibase.org/u/kmkrishna1223)
#### Post date: [October 27, 2022, 3:40am UTC](https://forum.liquibase.org/t/not-able-to-create-indexes-using-json-format-on-mongodb-and-unable-to-generate-change-logs-on-existing-mongodb-databases-to-capture-the-changes/7444/3 "2022-10-27T03:40:49Z")

</div>

Thanks for the response.  
I am not using text indexes and its working with XML change log .

Even tried with different approaches with json its failed to form keys as follows

```auto
[2022-10-27 03:39:24] FINE [liquibase.ext] Executing Statement: db.runCommand({"createIndexes": "person3", "indexes": [{**"key": {}}]}**);

```
