Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using MongoDB.Bson;
- using MongoDB.Bson.IO;
- using MongoDB.Driver;
- namespace TestGeospaticalHaystackIndexing {
- public static class Program {
- public static void Main(string[] args) {
- try {
- var server = MongoServer.Create("mongodb://localhost/?safe=true");
- var database = server["test"];
- var foo = database["foo"];
- foo.Drop();
- foo.Insert(new BsonDocument {
- { "pos", new BsonDocument { { "long", 34.2 }, { "lat", 33.3 } } },
- { "type", "restaurant" }
- });
- foo.Insert(new BsonDocument {
- { "pos", new BsonDocument { { "long", 34.2 }, { "lat", 37.3 } } },
- { "type", "restaurant" }
- });
- foo.Insert(new BsonDocument {
- { "pos", new BsonDocument { { "long", 59.1 }, { "lat", 87.2 } } },
- { "type", "office" }
- });
- var keys = new IndexKeysDocument {
- { "pos", "geoHaystack" },
- { "type", 1 }
- };
- var options = new IndexOptionsDocument {
- { "bucketSize", 1 }
- };
- foo.EnsureIndex(keys, options);
- var command = new CommandDocument {
- { "geoSearch", "foo" },
- { "near", new BsonArray { 33, 33 } },
- { "maxDistance", 6 },
- { "search", new BsonDocument { { "type", "restaurant" } } },
- { "limit", 30 }
- };
- var result = database.RunCommand(command);
- Console.WriteLine(result.Response.ToJson(new JsonWriterSettings { Indent = true }));
- } catch (Exception ex) {
- Console.WriteLine("Unhandled exception:");
- Console.WriteLine(ex);
- }
- Console.WriteLine("Press Enter to continue");
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment