0

I have a collection ('stops') with 14000 records imported from a CSV. Included in each record is some geospatial data, which I've converted into an array, so each essentially looks like this:

{
  _id: ...,
  // other fields
  "loc": [
    153.019073,
    -27.467834
  ]
}

When I run db.stops.ensureIndex({ loc: '2d' }) it gives the error:

location object expected, location array not in correct format

I guess that something's wrong in one of the fields, but I can't figure out which one. Any ideas?

1 Answer 1

1

The problem was that there was a single record which wasn't imported correctly (probably an empty line at the end of the file).

To find it (and later remove it), I used the $where operator:

db.stops.find({ $where: 'typeof this.loc[0] != "number"' })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.