Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Created October 16, 2020 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj-nitehawk/8248e6375d9655a53e10db8aa6bd626f to your computer and use it in GitHub Desktop.
Save dj-nitehawk/8248e6375d9655a53e10db8aa6bd626f to your computer and use it in GitHub Desktop.
geo search test
using MongoDB.Entities;
using System;
using System.Threading.Tasks;
namespace TestProg
{
internal static class Program
{
public class ArtGallery : Entity
{
public string Name { get; set; }
public Coordinates2D Location { get; set; }
}
private static async Task Main()
{
await DB.InitAsync("test");
await new[]
{
new ArtGallery {
Name = "Galleria Le-Pari",
Location = new Coordinates2D(48.8539241, 2.2913515)
},
new ArtGallery {
Name = "Versailles House Of Art",
Location = new Coordinates2D(48.796964, 2.137456)
},
new ArtGallery {
Name = "Poissy Arts & Crafts",
Location = new Coordinates2D(48.928860, 2.046889)
}
}.SaveAsync();
await DB.Index<ArtGallery>()
.Key(g => g.Location, KeyType.Geo2DSphere)
.Option(o => o.Background = false)
.CreateAsync();
var locEiffelTower = new Coordinates2D(48.857908, 2.295243);
var results = await DB.Find<ArtGallery>()
.Match(g => g.Location, locEiffelTower, 20000)
.ExecuteAsync();
foreach (var gallery in results)
{
Console.WriteLine(gallery.Name);
}
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment