SpatialQuery order function exception

Hi

i want to use order function with SpatialQuery but give the error.

let query = spatialQuery.from(‘locations’, ‘GetNearBy’)
.order(couchbase.ViewQuery.Order.DESCENDING) // give error in this line.
.stale(spatialQuery.Update.BEFORE)
.bbox(bbox)
.skip(filter.PageIndex)
.limit(filter.PageSize);
can you help me?

Hey @aolmez,

Would you be able to share what error you receiving?

Cheers, Brett

Hi @brett19

spatialQuery has not order function. how can order it?

my error :
spatialQuery.from(…).order is not a function

Hey @aolmez,

In order to generate an ordered list in this case, we would need to have some sort of relativity between entries within the result set. In the case of a spatial query, there is no relativity to sort by. Can you provide a bit more detail on the sorting behaviour you are looking for? You will likely need to perform your ordering on the client side.

Cheers, Brett

@brett19

i want to sort by created date of the nearest records.
How can sort records?

sample data:

{
“Author”: “aolmez”,
“BaseType”: 0,
“City”: “Ankara”,
“CreatedAt”: 636501547120000000
“VenueId”: “54211bf0498e0790438e02cd”,
“ViewerCount”: 0
},
{
“Author”: “aolmez”,
“BaseType”: 0,
“City”: “Ankara”,
“CreatedAt”: 636501546880000000,
“VenueId”: “54211bf0498e0790438e02cd”,
“ViewerCount”: 0
}

My views:

function (doc,meta) {
if (doc.Location) {
emit([{
“type”: “Point”,
“coordinates”:[doc.Location.longitude, doc.Location.latitude]
}], doc);

}
}