Understanding geospatial views

A Couchbase bucket can also store two-dimensional spatial records specifying longitude and latitude. If you want to create a view for spatial records, it can be done using a geospatial view. This is introduced as an experimental feature and can be used in the development environment only. You can refer to the documentation for any update on this.

The following document represents the location of the city, Mumbai, in the bucket:

{
"location" : 18.9750, 72.8258],
"city" : "Mumbai"
}

You can create geospatial view as follows:

function(doc, meta)
{
  if (doc.loc)
  {
     emit( {  type: "Point", coordinates: doc. location, }, doc.location);
  }
}

The key in the spatial view index can be any valid GeoJSON geometry value.

Get Learning Couchbase now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.