2
votes

I'm testing Azure DocumentDb to decide if we should change our database from mongodb to doucmentDb.

We have a database with 10.000+ locations in mongodb where the locations are saved as geojson. So it no problem to move our data, but how do I query my data using the linq provider in the .NET SDK?

We have our own implementation of geojson that we use with our mongodb, so we are not interested in changing our data model to depend on the spatial classes provided in the .NET SDK.

Is there a way to use to linq provider with custom spatial classes when querying DocumentDb?

1
Have you considered using node.js or the .NET integration of it, edge.js? It is a closer fit to your MongoDB mental model. You'd use the DocumentDB SDK for node.js in that case. No Linq but I created the (sql-from-mongo)[npmjs.com/package/sql-from-mongo] npm package to allow me to use MongoDB query syntax against DocumentDB. That might be a closer fit for your MongoDB background. IMHO the over reliance on object-orientation of C#, Java, etc. is an impedance mismatch with NoSQL (even Microsoft's NoSQL, DocumentDB) and server-side JavaScript is a perfect fit. - Larry Maccherone
Can you please provide your class definitions? The wrapper classes in the DocumentDB SDK are fully compliant to the GeoJSON standard and existi only to make it easy to serialize/deserialize - you should be able to use the same GeoJSON as MongoDB without making changes. - Aravind Krishna R.
We have created our own GeoJSON classes, that we use in our classes, and we are able to save them to the DocumentDb without any problems. The problem is when we are trying to query them using linq, we are unable to use the spatial linq querys because our model uses our own GeoJSON classes. - eNepper
@Larry In our solution today we have a data layer here all the technology specific querying are placed. Anywhere else we use linq to query our data layer. - eNepper

1 Answers

3
votes

DocumentDB has recently added support for spatial data types,and natively supports the GeoJSON standard: https://azure.microsoft.com/en-us/blog/announcing-geospatial-support-in-azure-documentdb/

Below is an example of using LINQ to do spatial queries in DocumentDB:

// An example document with spatial data
public class MyDocument 
{
    public string Id { get; set; }
    public Microsoft.Azure.Documents.Spatial.Point Location { get; set; }
}

// An example distance query - get all documents within 30 km of a given point
client.CreateDocumentQuery<MyDocument>(collection.SelfLink)
    .Where(x => x.Location.Distance(new Point(32.33, -4.66)) < 30000))