Giter VIP home page Giter VIP logo

Comments (2)

jsonking avatar jsonking commented on September 13, 2024

@alexandru-slobodcicov I'm thinking that the Statement implementations could execute the runCommand operation instead of the higher level driver helper methods.
There are two principal benefits:

1: options can be specified in the migrations themselves and are passed through to the database directly. No need to manually add support for options that change over time.

2: Works with a larger set of underlying mongo-driver versions; increasing adoption of this library.

Example: liquibase.ext.mongodb.statement.InsertOneStatement
Current Code:

@Override
public void execute(final MongoConnection connection) {
    final MongoCollection<Document> collection = connection.getDatabase().getCollection(getCollectionName());
    collection.insertOne(document);
}

Note that the current code doesn't support any options!

Modified Code:

@Override
public void execute(final MongoConnection connection) {
    Bson bson = createCommand();
    connection.getDatabase().runCommand(bson);
}

private Bson createCommand() {
    Document command = new Document("insert", getCollectionName());
    command.put("documents", Collections.singletonList(document));
    command.putAll(options);
    return command.toBsonDocument(Document.class, getDefaultCodecRegistry());
}

This is the strategy I used in PR #78 to add support for all options in the CreateCollectionStatement class

Finally there are currently two open issues (#71 and #80) relating to supporting the latest driver version.

The signature of the runCommand methods in the driver has not changed between version 3.12.x and 4.x; but collection.insertOne is no longer void and therefore fails at runtime. i.e using runCommand is a more stable interface to use and would provide greater chances of forward-compatibility.

Keen to hear your thoughts?

Jason

from liquibase-mongodb.

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

Hi @jsonking. Indeed worth changing where possible the Statemens to db.runCommand as you did for CreateCollectionStatement. Just want to mention that the initial approach was to stick to driver APIs until we identified that approximatively everything can be done from runCommand and adminCommand. The same is mentioned in README: A couple of Changes were implemented until identified that majority of the operations can be achieved using db.runCommand() and db.adminCommand(). So there is already the option to define runCommand and adminCommand in changesets with all the flexibility.

This particular issue is about having the Database instead of Connection in statements:
execute(final MongoConnection connection) -> execute(final MongoLiquibaseDatabase database)

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.