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

unable to find index for $geoNear query #6549

Closed
edjroz opened this issue Jun 1, 2018 · 1 comment
Closed

unable to find index for $geoNear query #6549

edjroz opened this issue Jun 1, 2018 · 1 comment

Comments

@edjroz
Copy link

edjroz commented Jun 1, 2018

What is the current behavior?
Setting up a '2dsphere' index doesn't seem to be working

I'm trying to set up a schema and query some documents that I've inserted with proper geoJSON structure, however when I try to query but $near I get this error message:

Sort: {}
Proj: {}
 planner returned error: unable to find index for $geoNear query
    at queryCallback (/Users/edjroz/Repos/.tnp/cityapp-gcp/node_modules/mongodb-core/lib/cursor.js:244:25)
    at /Users/edjroz/Repos/.tnp/cityapp-gcp/node_modules/mongodb-core/lib/connection/pool.js:544:18
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'MongoError',
  message: 'error processing query: ns=ca.dummy2Tree: GEONEAR  field=loc maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query',
  ok: 0,
  errmsg: 'error processing query: ns=ca.dummy2Tree: GEONEAR  field=loc maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query',
  code: 2,
  codeName: 'BadValue' }

using schema.indexes() gives me the output [ [ { location: '2dsphere' }, { background: true } ] ]

however if I try to go check indexes on mongo by using the CLI
db.example.getIndexes() it returns an empty array []

import mongoose from 'mongoose';

const schema = new mongoose.Schema({
  location: {
    type: { type: String, default: 'Point', enum: ['Point'] },
    coordinates: [Number],
    // index: '2dsphere',
  },
  title: {
    type: String,
    required: true,
  },
});
schema.index({ location: '2dsphere' });
const issueModel = mongoose.model('dummy', schema);

export default issueModel;
import issueModel from '../util/models/dummy';

const foo = async (req, res) => {
  try {
    const documents = await model.find({ loc: { $near: { type: 'Point', coordinates: [0.1, 0.2] } } }),
    res.status(200).send(response);
  } catch (e) {
    console.log(e);
    res.status(400).send({ error: new Error(e) });
  }
};

What is the expected behavior?
query any documents close to that location

Please mention your node.js, mongoose and MongoDB version.
mongo: 3.4.0
NodeJs: Carbon LTS (8.9.4)
Mongoose: 5.1.3

@edjroz
Copy link
Author

edjroz commented Jun 1, 2018

It seems that my query was the mistake, I noticed right after posting this. the query tries to find the key loc which doesn't exist in the model schema.

@edjroz edjroz closed this as completed Jun 1, 2018
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

1 participant