Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mongodb driver directly? #526

Closed
BorntraegerMarc opened this issue Dec 7, 2017 · 9 comments
Closed

Use mongodb driver directly? #526

BorntraegerMarc opened this issue Dec 7, 2017 · 9 comments
Labels

Comments

@BorntraegerMarc
Copy link
Contributor

Hi @wzrdtales sorry if I'm asking something that has already been posted - but I didn't find anything in the documentation or in the existing issues.

I wanted to ask if it is possible to use the mongodb driver directly? Like this for example:

exports.up = function (db) {
  return db.driver.collectionName.find({id: 'ID'}).then((collection) => {
    collection.property = 'newValue';
    return collection.save();
  });
}

The idea: I want to only update one property in one entry in the DB.

The reason: We have "base data" defined in our app that get's initialized (and updated) with every release. This base data needs maintenance and it would be awesome if maintenance could be done with node-db-migrate.

Thanks for answering!

@BorntraegerMarc
Copy link
Contributor Author

Friendly ping to @wzrdtales 🙂

@wzrdtales
Copy link
Member

Thanks for bugging me :)

The answer is: not yet really, but this was asked a few times already, i wouldn't be against such option, as this would be an equivalent to runSql. Do you want to give this a shot?

@wzrdtales
Copy link
Member

And merry christmas btw. :)

@BorntraegerMarc
Copy link
Contributor Author

Merry Christmas to you too :)

Could you point me to the correct place where an export would need to be added? I tried to dig into the new code but the new structure is a bit confusing to me 😄

@wzrdtales
Copy link
Member

For sure!

Here you go edit the mongo driver:

https://github.com/db-migrate/mongodb/blob/master/index.js#L10

When you add a new method that needs to be added to one of the interfaces, here is an example on how to do that:

https://github.com/db-migrate/mysql/blob/master/index.js#L420

@Aron4u
Copy link

Aron4u commented Jan 10, 2018

i saw that the functions are there and merged ... how do i use this feature now? like you discribed in your inital post?

when i try

exports.up = function (db) {
  return db.driver.collectionName.find({id: 'ID'}).then((collection) => {
    collection.property = 'newValue';
    return collection.save();
  });
}

the db.driver is already undefined :(

@BorntraegerMarc
Copy link
Contributor Author

Use it like this:

return db._run('getDbInstance')
        .then(dbDriver => {})

@stale
Copy link

stale bot commented Feb 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ks-s-a
Copy link

ks-s-a commented May 16, 2018

You could faced to migration terminating problem. Just close the dbDriver to avoid it.

return db._run('getDbInstance').then((dbDriver) => {
    return dbDriver.collection('collection_name')
      .findAll({
        prop: 'value'
      })
      .then(() => {
        return dbDriver.close();
      });
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants