spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Add index creation statements to mongo db DDL script

Open fmbenhassine opened this issue 9 months ago • 3 comments

Currently, the mongo db DDL script schema-mongodb.jsonl contains collections creation statements, but not index creation statements.

This issue is to add index creation statements to the script similar to what is in schema-mongodb.js.

Reference:

https://www.mongodb.com/docs/manual/reference/command/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes

fmbenhassine avatar Feb 12 '26 06:02 fmbenhassine

I am not clear as which one is the idiomatic version. Why do we have two and is there a benefit to use one over the other?

snicoll avatar Mar 10 '26 16:03 snicoll

The js version requires mongosh, but not all mongo users use that shell. Moreover, that js script might require users to change the database name if it's different from the default one, while the jsonl is independent from the db name. I am not a mongodb expert, but IIUC, database commands in the jsonl version provide more details than the js helper methods (here is an excerpt from the link above):

Helper methods are convenient for mongosh users, but they may not return the same level of information
as database commands.

The jsonl version is also language agnostic and easier to work with in conjunction with the MongoTemplate API. In fact, MongoTemplate#executeCommand expects database commands and not js statements, and it was easier in our context to initialise the MongoDB instance by applying database commands line by line from a file (similar to JDBC) rather than trying to mimic them with methods from the MongoTemplate API (defc0c1eb59c67106d46cca429ef40f0ca32cfcd)

We kept the js version as a convenience for mongosh users.

fmbenhassine avatar Mar 13 '26 09:03 fmbenhassine

I'd like to work on this. I'll add createIndexes commands to schema-mongodb.jsonl matching the indexes in schema-mongodb.js, grouping indexes by collection.

PreAgile avatar Apr 05 '26 10:04 PreAgile