liquibase / liquibase-mongodb

MongoDB extension for Liquibase
Apache License 2.0
54 stars 46 forks source link

Cannot populate MongoDb using insertOne #89

Closed miptildar closed 3 years ago

miptildar commented 3 years ago

I am running Liquibase MongoDb extension as a Docker image using a Dockerfile from the following repository: https://github.com/mmarcon/liquibase-mongo-docker

As a changelog I used this simple json:

{
    "databaseChangeLog": [
        {
            "changeSet": {
                "id": "4",
                "author": "Nick",
                "comment": "Populate person table",
                "changes": [
                    {
                        "insertOne": {
                            "collectionName": "person",
                            "document": {
                                "$rawJson": {
                                    "name": "Alexandru Slobodcicov",
                                    "address": "Moldova"
                                }
                            }
                        }
                    }
                ]
            }
        }
    ]
}

Results

Liquibase is being run successfully, collection is being created, but no data is populated.

Here are Liquibase logs:

2021-01-29T16:09:02.1994518Z [2021-01-29 16:09:02] INFO [com.mongodb.diagnostics.logging.JULLogger log] Opened connection [connectionId{localValue:5, serverValue:5}] to ex-mongodb:27017
2021-01-29T16:09:02.2027671Z [2021-01-29 16:09:02] INFO [com.mongodb.diagnostics.logging.JULLogger log] Monitor thread successfully connected to server with description ServerDescription{address=ex-mongodb:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 9]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=2012900}
2021-01-29T16:09:02.2177238Z [2021-01-29 16:09:02] INFO [com.mongodb.diagnostics.logging.JULLogger log] Opened connection [connectionId{localValue:6, serverValue:6}] to ex-mongodb:27017
2021-01-29T16:09:02.2275768Z [2021-01-29 16:09:02] INFO [liquibase.ext] Create Database Lock Collection: extricatordb.DATABASECHANGELOGLOCK
2021-01-29T16:09:02.289213Z [2021-01-29 16:09:02] INFO [liquibase.ext] Created database lock Collection: DATABASECHANGELOGLOCK
2021-01-29T16:09:02.2900146Z [2021-01-29 16:09:02] INFO [liquibase.ext] Adjusting database Lock Collection with name: extricatordb.DATABASECHANGELOGLOCK
2021-01-29T16:09:02.3016375Z [2021-01-29 16:09:02] INFO [liquibase.ext] Adjusted database Lock Collection with name: extricatordb.DATABASECHANGELOGLOCK
2021-01-29T16:09:02.3320803Z [2021-01-29 16:09:02] INFO [liquibase.ext] Lock Database
2021-01-29T16:09:02.3436049Z [2021-01-29 16:09:02] INFO [liquibase.ext] Successfully Acquired Change Log Lock
2021-01-29T16:09:02.3890683Z [2021-01-29 16:09:02] INFO [liquibase.servicelocator] Cannot load service: liquibase.parser.ChangeLogParser: liquibase.nosql.parser.json.JsonNoSqlChangeLogParser Unable to get public no-arg constructor
2021-01-29T16:09:02.6942666Z [2021-01-29 16:09:02] INFO [liquibase.ext] Create Database Change Log Collection
2021-01-29T16:09:02.6945298Z [2021-01-29 16:09:02] INFO [liquibase.ext] Creating database history collection with name: extricatordb.DATABASECHANGELOG
2021-01-29T16:09:02.7565717Z [2021-01-29 16:09:02] INFO [liquibase.ext] Created database history collection : extricatordb.DATABASECHANGELOG
2021-01-29T16:09:02.7568709Z [2021-01-29 16:09:02] INFO [liquibase.ext] Adjusting database history Collection with name: extricatordb.DATABASECHANGELOG
2021-01-29T16:09:02.7570992Z [2021-01-29 16:09:02] INFO [liquibase.ext] Adjusted database history Collection with name: extricatordb.DATABASECHANGELOG
2021-01-29T16:09:03.0824029Z [2021-01-29 16:09:03] INFO [liquibase.nosql] Changeset changelog/create_settlements_workspace.json::4::Nick
2021-01-29T16:09:03.0826871Z [2021-01-29 16:09:03] INFO [liquibase.nosql] Populate person table
2021-01-29T16:09:03.1542302Z [2021-01-29 16:09:03] INFO [liquibase.changelog] Document inserted into collection person
2021-01-29T16:09:03.1547072Z [2021-01-29 16:09:03] INFO [liquibase.changelog] ChangeSet changelog/create_settlements_workspace.json::4::Nick ran successfully in 72ms
2021-01-29T16:09:03.1662403Z [2021-01-29 16:09:03] INFO [liquibase.ext] Release Database Lock
2021-01-29T16:09:03.1693298Z [2021-01-29 16:09:03] INFO [liquibase.ext] Successfully released change log lock
2021-01-29T16:09:03.1715455Z [2021-01-29 16:09:03] INFO [com.mongodb.diagnostics.logging.JULLogger log] Closed connection [connectionId{localValue:6, serverValue:6}] to ex-mongodb:27017 because the pool has been closed.
2021-01-29T16:09:03.1745137Z Liquibase: Update has been successful.

And a screenshot from MongoDb Compass

image

Could you say me, why data is not being populated?

┆Issue is synchronized with this Jira Bug by Unito

alexandru-slobodcicov commented 3 years ago

Hi @miptildar could be because it couldn't initialize the right JsonParser. Please see the issue https://github.com/liquibase/liquibase-mongodb/issues/53 Could please check if you have this in your logs: [2020-11-07 13:08:54] INFO [liquibase.servicelocator] Cannot load service: liquibase.parser.ChangeLogParser: Provider liquibase.nosql.parser.json.JsonNoSqlChangeLogParser could not be instantiated or: [2020-11-01 15:31:13] INFO [liquibase.servicelocator] Cannot load service: liquibase.parser.ChangeLogParser: liquibase.nosql.parser.json.JsonNoSqlChangeLogParser Unable to get public no-arg constructor Could be that you don't have dependencies in your classpath {liquibase_home}/lib: jackson-annotations-2.11.3.jar jackson-core-2.11.3.jar jackson-databind-2.11.3.jar

See README.md instructions: For the command line is required to copy to [liquibase]/lib libraries : jackson-annotations-2.11.3.jar, jackson-core-2.11.3.jar, jackson-databind-2.11.3.jar

Most probably is picked the default parser thus the document parameter is set as empty

miptildar commented 3 years ago

Thank you! Your solution is correct.

I added these lines to the original Dockerfile and MongoDb started getting populated:

RUN wget -O /liquibase/lib/jackson-annotations-2.12.1.jar https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.12.1/jackson-annotations-2.12.1.jar
RUN wget -O /liquibase/lib/jackson-core-2.12.1.jar https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.12.1/jackson-core-2.12.1.jar
RUN wget -O /liquibase/lib/jackson-databind-2.12.1.jar https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.12.1/jackson-databind-2.12.1.jar
alexandru-slobodcicov commented 3 years ago

Thank you, and waiting for new feedback :)