Giter VIP home page Giter VIP logo

Comments (12)

DarrinProtag avatar DarrinProtag commented on September 13, 2024

I think you want something like this in AdminCommandStatement.java (I need to figure out how to test this change):
(deleted incorrect code)

from liquibase-mongodb.

DarrinProtag avatar DarrinProtag commented on September 13, 2024

Sorry, I was browsing the older code base. I think this might work:

    public Document run(final MongoLiquibaseDatabase database) {
        MongoDatabase adminDB = ((MongoConnection)database.getConnection()).getMongoClient().getDatabase(database.getSystemSchema());
        return adminDB.runCommand(command);
    }

from liquibase-mongodb.

DarrinProtag avatar DarrinProtag commented on September 13, 2024

To add some detail, here is the command I was attempting:

adminCommand(command: '{shardCollection: "darrin.player_info_static", key: {location: 1, _id: 1}, unique: true} ')

Also, I forked the project and made the patch I suggested above, and it appears to be working!

from liquibase-mongodb.

alexandru-slobodcicov avatar alexandru-slobodcicov commented on September 13, 2024

Thank you @DarrinProtag, will go on with your solution if turns out it is required for adminCommand.

mongo documentation says that it basically does the same you described:
https://docs.mongodb.com/manual/reference/method/db.adminCommand/

db.adminCommand runs commands against the admin database regardless of the database context in which it runs. The following commands are equivalent:
db.getSiblingDB("admin").runCommand(<command>) db.adminCommand(<command>)

And yes because of that java driver do not contain api for adminCommand we have to run it via runCommand on admin db.
Will add integration tests examples and probably will use properties to provide db name so that liquibase changes are portable and db name not hardcoded

from liquibase-mongodb.

alexandru-slobodcicov avatar alexandru-slobodcicov commented on September 13, 2024

Merged will be available in 4.3.1.1 when released

from liquibase-mongodb.

alexandru-slobodcicov avatar alexandru-slobodcicov commented on September 13, 2024

Hi @DarrinProtag please note https://github.com/liquibase/liquibase-mongodb/releases/tag/liquibase-mongodb-4.3.1.1 is released. Could you please try it out?

from liquibase-mongodb.

DarrinProtag avatar DarrinProtag commented on September 13, 2024

Hi @DarrinProtag please note https://github.com/liquibase/liquibase-mongodb/releases/tag/liquibase-mongodb-4.3.1.1 is released. Could you please try it out?

No problem. I switched my build to this released version, and it works fine. Thank you. I am now able to set up sharding, shard my collections, and set the shard keys!

For the next person...I'm using groovy formatted changelogs, and doing things like this... And need no manual setup steps, now.

        adminCommand(command: '{enableSharding: "${database.name}" } ')
        adminCommand(command: '{shardCollection: "${database.name}.player_info_static", key: {location: 1, _id: 1}, unique: true} ')

from liquibase-mongodb.

Yuriy-Lukashevich avatar Yuriy-Lukashevich commented on September 13, 2024

Hi @DarrinProtag. I'm trying to add luquibase to my project. We are using Cosmosdb Mongodb API.
I would appreciate it very much if you could share how to add to xml or json script operation like this:
db.runCommand({customAction: "CreateCollection", collection: "name", offerThroughput: 400, shardKey: "partition_key", indexes: [{key: {_id: 1}}, {key: {partition_key: 1, some_key: 1},unique: true}]});

from liquibase-mongodb.

DarrinProtag avatar DarrinProtag commented on September 13, 2024

https://docs.liquibase.com/workflows/database-setup-tutorials/mongodb.html - if you twist open the Examples section, there are examples of XML commands to create collections. I haven't found great examples of json (or gradle; which we use) formatted commands. I just tried permutations of syntax until it started making sense to me.

These are the libraries we included:
plugins{
id 'org.liquibase.gradle' version '2.0.4'
}
dependencies{
liquibaseRuntime "org.liquibase.ext:liquibase-mongodb:${project.liquibaseMongodbVersion}" //4.3.1
liquibaseRuntime "org.liquibase:liquibase-core:${project.liquibaseCoreVersion}" //4.3.1
liquibaseRuntime "org.liquibase:liquibase-groovy-dsl:${project.liquibaseGroovyVersion}" // 3.0.0
}

I assume there is a json-dsl library you'd need to include if you wanted to parse json command files.

I assume cosmo will accept a regular mongo connection string, as opposed to needing a custom cosmo sdk compiled against liquibase. No doubt, Azure (or whoever) wants fancy auth set up locally before it will respond, though.

To run stuff from gradle build files...
// Run liquibase.update to get schema/indexes up to date.
// In the future, to manage multiple clusters in one mongo,
// use -PrunList stuff from the docs: https://github.com/liquibase/liquibase-gradle-plugin
liquibase {
activities {
local {
// parameters in each activity are from -- for liquibase...
// https://docs.liquibase.com/commands/home.html
changeLogFile 'datastore/src/main/resources/liquibase/changelogs.groovy'
dataOutputDirectory 'datastore/src/main/resources/liquibase/changelog_out'
url 'mongodb://localhost:27017/darrin'
// username ''
// password ''

        // Needs to run with -Ddatabase.name=darrin to fix up changelog contents (e.g. stuff like "${database.name}.unique_item"}.
        changeLogParameters([ "database.name" : "darrin"])
        classPath "$rootDir"
    }
}

}

Sorry I can't be more help about the json format.

from liquibase-mongodb.

Yuriy-Lukashevich avatar Yuriy-Lukashevich commented on September 13, 2024

Darrin thank you for your reply. I red tutorial, but it has no useful examples in my case. I have no issues with connection or running simple commands on CosmosDB MongoDB, but runCommand with customAction won't work.

from liquibase-mongodb.

DarrinProtag avatar DarrinProtag commented on September 13, 2024

Its a bit of a leap into deep water, but the liquibase-mongo source is online. If you spend awhile staring at it, you might figure out whether customAction is supported or if there is a generic command that you could send it through. And if not, maybe you could see how to add a new command that supports it. Alexandru was quite kind about taking suggested changes, so you may not have to use a private fork for very long.

https://github.com/liquibase/liquibase-mongodb/tree/main/src/main/java/liquibase/ext/mongodb

from liquibase-mongodb.

nwinkler avatar nwinkler commented on September 13, 2024

@Yuriy-Lukashevich I'm trying to run Liquibase-MongoDB on CosmosDB, but I'm running into some errors when Liquibase is starting up, complaining about the collMod command not being supported on CosmosDB.

Did you have to use any special configuration for Liquibase to make it work on CosmosDB?

from liquibase-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.