Understanding the basic geospatial data & queries

Hi, just trying to understand the basic geospatial data & queries. In

Exploring the Data

I inspected an entry in the newly-created restaurants collection in
mongosh, with


which returns a document like the following:

   location: {
      type: "Point",
      coordinates: [-73.856077, 40.848447]
   name: "Morris Park Bake Shop"

However, what I found in the MongoDB Atlas UI, the actual record looks like this:

{"_id":{"$oid":"5eb3d668b31de5d588f4292e"},"address":{"building":"1007","coord":[{"$numberDouble":"-73.856077"},{"$numberDouble":"40.848447"}],"street":"Morris Park Ave","zipcode":"10462"},"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":{"$numberLong":"1393804800000"}},"grade":"A","score":{"$numberInt":"2"}},{"date":{"$date":{"$numberLong":"1378857600000"}},"grade":"A","score":{"$numberInt":"6"}},{"date":{"$date":{"$numberLong":"1358985600000"}},"grade":"A","score":{"$numberInt":"10"}},{"date":{"$date":{"$numberLong":"1322006400000"}},"grade":"A","score":{"$numberInt":"9"}},{"date":{"$date":{"$numberLong":"1299715200000"}},"grade":"B","score":{"$numberInt":"14"}}],"name":"Morris Park Bake Shop","restaurant_id":"30075445"}

So is the db.restaurants.findOne() a function that is doing its own data massaging?

As I want to understand what data format I can/should use for geospatial data in my DB, so that I can make use of the geospatial queries, yet, what the above query returned differs greatly with what was stored.

Any clarification/explanation please? thx.

Did you really

and get simply the following as output

or you simply cut-n-paste what is in the documentation?

I think you simply cut-n-paste what is in the documentation because without a projection you will get an _id. I think that in the documentation they only shown the fields important to the discussion.

I think you are really looking at the same document. One is represented as EJSON (the one with $oid) and the other is only part of the whole document to make the documentation easier to read.

So no, findOne() is not doing its own data massaging.


Ah, indeed, there is an _id field. Here is the actual output from my side:

> db.restaurants.findOne()
  _id: ObjectId("55cba2476c522cafdb053add"),
  location: { coordinates: [ -73.856077, 40.848447 ], type: 'Point' },
  name: 'Morris Park Bake Shop'


What I’m asking is that, in the sample data, it was:


Yet the db.restaurants.findOne() is showing me totally different thing.

So if findOne() is not doing its own data massaging, then where the differences are coming from?

Or I am looking at the wrong collection?


I was looking into the sample_restaurants collection in the MongoDB Atlas UI, where the mongoimport command in the tutorial didn’t specify a database…

Most likely you are.

From the screenshot you supplied (the part with show dbs), sample_restaurants is a database, not a collection.

What I suspect is that your mongoimport used the test database. In the same Atlas UI, do the following commands and share the output:

use test
show collections
use sample_restaurants
show collections

Also share the mongoimport command you used.

Ah, indeed:


Problem solved. Thanks.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.