Executing JS script file from liquibase mongoDB changeset

Hello,
I want to integrate liquibase into our db as a version control tool, we are using Java with spring(not boot with beans)
the following link shows how we can execute liquibase schema changes:

We are using mongodb and I saw that there is a new driver called liquibase mongo(on maven).

however we are running the schema changes from js script files,
Is that possible to execute js file using liquibase-mongo? I know for sql you have a tag with the script location in it
Many thanks,
Roie

1 Like

One more issue:
the java class in the readme file:

it is not lined up with 4.1.1 mongoDB liquibase version,
can you please update the guide? (a full working example would be amazing !! :slight_smile: )

Hi @roie!

To answer your question above, when your changeset points to a script, it is looking for valid sql that would be valid if you were to run it directly against the db platform. A js script would not work but, liquibase can take sql and run it b/c it just opens a jdbc connection to the target db, and executes sql.

Originally, I believe you are trying to version your db changes. If you create sql, or sql changelogs and save them in a directory structure in your repo, those scripts will be versioned. The database maintains its individual version level in its databasechanglelog table.

HTH,

Ronak

Hi,
I may have not explained myself currectly
In a Mongo db change set, As a follow up, I have the following function:

function createNewTibcoConfig(oldConfig) {
    const newObject = {"a": "blabla"};
    if (condition) {
        //do something with newObject 
    } else { 
		//do something else with newObject 
    }
	db.collection.update({ _id: newObject._id }, { $set: { "oldConfig": newObject } });
}

How can Execute the following function(or only content of function) in an changeSet xml file?

<changeSet id="1" author="bob">
 <!--How can I execute the content of the function here? is it possible? keep in mind there is an if condition in the function -->
</changeSet>

Hi @roie, answered in the github as well:
this info you can get from README as well. Answered the same stack overflow.
liquibase-mongodb extension is an alternative to the tools that are wrapping MJS(see mongeeze) into a eval method of mongo java driver. Was developed due to the fact that eval was deprecated in Mongo. You can look into runCommand option(supported by liquibase-mongodb) which lets you implement the most of the required operations including multiple updates. Indeed, will doublecheck if mongo is going to support deprecated eval in the future. Actually the extension was implemented to workaround what you are asking and all the Liquibase changes are implemented close to Mongo Java Driver APIs.
Happy to support you on how to convert your JS to runCommand entries.

IMPORTANT
Starting in version 4.2, MongoDB removes the eval command. The deprecated db.eval(), which wraps the eval command, can only be run against MongoDB 4.0 or earlier versions. For behavior and example, refer to the 4.0 or earlier version of the manual.