Searching in near by location users

iam pasting a sample json data

'{

"_id" : "bmZ4zj4LsQTfQuNuK",
"createdAt" : ISODate("2015-08-11T08:14:23.579Z"),
"services" : {
    "google" : {
        "accessToken" : "ya29.zgEaK4__zUZ_cyIbFePUG_haH0Q6OAIiw-rMAD3dSoW2R7Hhf4NKaYiv8yao8PslqVHB_A",
        "idToken" : "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc3N2YyYjI0MmRiZjQxY2Y1YThlZTcwODQ1YjYwNDZjMTA4Njk2NTEifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXRfaGFzaCI6Il9sa0M0NWVRa1JCYmE5aVl0VXFvMUEiLCJhdWQiOiI1ODA0MTA1MzA1OTUtN2I0Y3VlbXBqNXAzb3Z0NGhwdjUxN2x2MWRuYTNxNGguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDc3NDYwOTY0OTQwNTAwNDgzMTUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXpwIjoiNTgwNDEwNTMwNTk1LTdiNGN1ZW1wajVwM292dDRocHY1MTdsdjFkbmEzcTRoLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJiaGF2bmFqZDkxQGdtYWlsLmNvbSIsImlhdCI6MTQzOTQ0NTEyOSwiZXhwIjoxNDM5NDQ4NzI5fQ.er9uigCmyu7fK7twlO7nOzyFxSQh_xffNJ1nJx97IPYXfU5LigSQKlettRLp-Q_IaSS-AVe5itTjnrzMR6_iTy-qyEuYLnSWbTSK5sdn2npqaZ1WuDhZcjvKL-Im1Uq2OO78_9Ocmr0xJGdBpPnqtZWVL5MXKoNt48PV1DZM8TxMSCdaR-m7pgldGb9jdM0McXPIRtIIXSCxLOJxTWwVqDk69D5nxtWTgTDSOOOTG6jqjLYavMVKpQgxe4RslGiepkhyivn79e7Cj1zoYYdJs3RheDXhfo5M7kQwlKMipgOdtis-lnwgixJGlTGSY6kGFPMxEPLIxevOn10mepoYwQ",
        "expiresAt" : 1439448729870.0000000000000000,
        "id" : "107746096494050048315",
        "email" : "bemail@gmail.com",
        "verified_email" : true,
        "name" : "Bhavna Jd",
        "given_name" : "Bhavna",
        "family_name" : "Jd",
        "picture" : "https://lh4.googleusercontent.com/-XTrSHjAevaQ/AAAAAAAAAAI/AAAAAAAACmE/2SjCQG4sfUg/photo.jpg",
        "locale" : "en",
        "gender" : "female"
    },
    "resume" : {
        "loginTokens" : [ 
            {
                "when" : ISODate("2015-08-13T05:52:10.057Z"),
                "hashedToken" : "6HMkKAAJ41IODjdvjWqHIrbBd4tH6JSElW2YqlYwWAQ="
            }
        ]
    }
},
"profile" : {
    "name" : "Bhavna d",
    "location" : {
        "lat" : 19.2158777000000001,
        "lng" : 73.0957705999999945
    },
    "image" : "/cfs/files/images/6QEotuGhSWob28sBq"
},
"registered_emails" : [ 
    {
        "address" : "email@gmail.com",
        "verified" : true
    }
],
"status" : {
    "online" : true,
    "lastLogin" : {
        "date" : ISODate("2015-08-13T05:52:10.175Z"),
        "ipAddr" : "127.0.0.1",
        "userAgent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"
    },
    "idle" : false
}

}

i want to search based on nearest to him iam storing lat and long
"location" : {
“lat” : 19.2158777000000001,
“lng” : 73.0957705999999945
},’

i know $near command
but how can i use it any xample pls

For heaven’s sake, format that mess!

{
   // formatted code
}
// wrapped in ```

thanks for the attention, but any tool or site to format the code

Yeah, he told you. Just do ``` before and after the code

You just need to edit your post and put three ` on the line before and after your code.
https://help.github.com/articles/markdown-basics/#multiple-lines

EDIT: @benjick beat me to it, I spent 5 mins looking for markdown doco!

got it thanks mordax

This is how I’m using it:

// collection.js
Rooms = new Mongo.Collection("rooms");
if(Meteor.isServer) {
	Rooms._ensureIndex({ location : "2dsphere" });
}

// publish.js
Meteor.publish("rooms-nearby", function (lat, lng) {
	return Rooms.find({
		location:{
			$near:{
				$geometry:{
					type: "Point",
					coordinates:[lat, lng]
				}, 
				$maxDistance:5000000
			}
		}
	}, {
		fields: {
			name: 1,
			_id: 1,
			location: 1
		}
	});
});

// subscribe.js
var location = Geolocation.latLng() || { lat: 0, lng: 0 };
Meteor.subscribe("rooms-nearby",location.lat,location.lng);

Using this package: https://atmospherejs.com/mdg/geolocation

1 Like

I will just add that $near is forcing fallback to polling driver mode for this query, it is not so realtime as oplog.

What type must be set to lat and lng? Becouse i use simpleschema and need to specify that value