MONGO queries how many meters away from a point to thank for the data provided. Thanks to the MVC demo. It's all kind of a thank-you document anyway.

Source: Internet
Author: User

I went to an interview yesterday.

Asked for a moment Mong.

I remember Mong supported the geo-index, and said a bit.

And then the interviewer says how many meters to look at a certain point, how can this be achieved? I was so confused ....

Go back and check it out. Test data found (metric Yes)

Bsonelement Bsonele = new Bsonelement ("Address", "Nanjing Zhonghua Gate");

/*
* Create test data:
Db.mapinfo.insert ({"Address": "Nanjing Lukou International Airport", "Loc": {"type": "Point", "coordinates": [118.783799, 31.979234]})
Db.mapinfo.insert ({"Address": "Nanjing Pukou Park", "Loc": {"type": "Point", "coordinates": [ 118.639523,32.070078]})
Db.mapinfo.insert ({"Address": "Nanjing railway Station", "Loc": {"type": "Point", "coordinates": [ 118.803032,32.09248]})
Db.mapinfo.insert ({"Address": "Nanjing Xinjiekou", "loc": {"type": "Point", "coordinates": [ 118.790611,32.047616]})
Db.mapinfo.insert ({"Address": "Nanjing Zhang Fu Yuan", "loc": {"type": "Point", "coordinates": [ 118.790427,32.03722]})
Db.mapinfo.insert ({"Address": "Nanjing Sanshan Street", "Loc": {"type": "Point", "coordinates": [ 118.788135,32.029064]})
Db.mapinfo.insert ({"Address": "Nanjing Zhonghua Gate", "loc": {"type": "Point", "coordinates": [ 118.781161,32.013023]})
Db.mapinfo.insert ({"Address": "Nanjing Ender Gate", "loc": {"type": "Point", "coordinates": [ 118.768964,31.99646]})
* */

Mong_sql
/*
* Db.mapinfo.find (
* {
* "LOC":
* {
* "$near":
* {
* "$geometry":
* {
* "type": "Point", "coordinates": [118.783799, 31.979234]
* },
* "$maxDistance": 5000
}
*}
*}
*). Limit (50);
*/


Point of query
Double[] Array = {118.803032, 32.09248};

Bsonvalue bs = bsonvalue.create (array);

Bsonelement Bsonele = new Bsonelement ("coordinates", BS);

var query = new Querydocument ("type", "point");

Query. ADD (Bsonele);

var query1 = new Querydocument ("$geometry", query);

Distance from the point of how many meters
Query1. ADD ("$maxDistance", 50000);

var query2 = new Querydocument ("$near", Query1);

var query3 = new Querydocument ("Loc", Query2);

Imongoquery q= query.eq ("coordinates", BS);

mongocursor<mapinfo> mi = _mapinfos. Find (Query3). Setlimit (50);

Feel:

1: Keep adding objects to the object as well as objects in the MONGO.

The 2:ado executes SQL statements for the server, and Mongo.driver executes Bson.

MONGO queries how many meters away from a point to thank for the data provided. Thanks to the MVC demo. It's all kind of a thank-you document anyway.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.