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

Add support for Mongo 2dsphere indexes #16

Open
mefernandez opened this issue Jun 24, 2017 · 1 comment
Open

Add support for Mongo 2dsphere indexes #16

mefernandez opened this issue Jun 24, 2017 · 1 comment

Comments

@mefernandez
Copy link

mefernandez commented Jun 24, 2017

From this example:
https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/#prerequisites

It would be nice if db-migrate could support this:
db.restaurants.createIndex({ location: "2dsphere" })

This currently can't be done with addIndex NoSQL API.

Workaround: loading native mongodb driver:

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const url = 'mongodb://mongo:27017/test';

exports.up = function(db, callback) {
  MongoClient.connect(url, function(err, dbnative) {
        assert.equal(null, err);
        assert.notEqual(null, dbnative);
        dbnative.collection('ubicaciones').createIndex({ location: "2dsphere" })
        dbnative.close();
        callback();
      });
  return null;
}

<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/46557329-add-support-for-mongo-2dsphere-indexes?utm_campaign=plugin&utm_content=tracker%2F12293389&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F12293389&utm_medium=issues&utm_source=github).
</bountysource-plugin>
@madmxg
Copy link

madmxg commented Nov 5, 2020

Another workaround

exports.up = async function (db) {
  const options = { run_on: new Date() };
  const mongoDbNative = await db._run('getDbInstance', null, options);
  await mongoDbNative
    .collection(COLLECTION_NAME)
    .createIndex(
      { location: '2dsphere' },
      { name: INDEX_NAME, background: true }
    );
  await mongoDbNative.close();
};

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

No branches or pull requests

2 participants