0

How to convert this command for c# .net?

db.logs.aggregate([
   {
 $geoNear: {
    near: { type: "Point", coordinates: [ lng , lat ] },
    distanceField: "dist.distance",
    maxDistance: 5,
    includeLocs: "dist.location",
    num: 1000,
    spherical: true
 },
}
])
0

1 Answer 1

1

Finally, It's work fine.

                    BsonDocument geoPoint = new BsonDocument
                                {
                                    {"type","Point"},
                                   {"coordinates",new BsonArray(new Double[]{double.Parse(lon), double.Parse(lat)})}
                                };

                    BsonDocument query = new BsonDocument
                                {
                                    {
                                        "$eq", new BsonArray {"City", "Bangkok" }
                                    }
                                };


                    BsonDocument geoNearOptions = new BsonDocument
                                {
                                    {"spherical", true},
                                    {"limit", 10000}, //need to test to see what limit is appropriate, should we do a filter first?
                                    {"maxDistance", 400},
                                    {"query",filter},
                                    {"near",geoPoint},
                                    {"distanceField","dist.distance"},
                                    {"includeLocs", "dist.location"},
                                };

                    var stage = new BsonDocumentPipelineStageDefinition<BsonDocument, BsonDocument>(new BsonDocument { { "$geoNear", geoNearOptions } });
                    var colAggregate = collection2.Aggregate().AppendStage(stage).Sort(new BsonDocument { { "_id", 1 } });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.