Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My mongoDB collection has all three types of shapes. A point is stored as

{
 'CE_NO': '_',
 'E_NAME': 'RAILWAY BOOKING CENTER', 
 'SRCTYPE': 'Facility',
 'geom': {
         'coordinates': [
                         77.6221694946289,
                         12.93125057220459
                        ],
         'type': 'Point'},
 'EMAIL': '_', 
 'ID': 2.0, 
 'WEBSITE': '_', 
 '_id': ObjectId('53329166a6e10b0b68beaeb9'), 
 'LOCALITY': 'KORAMANGALA',
 'SUB_CAT': 'BOOKING CENTER',
 'FAX': '_', 
 'ROAD_NAME': '17TH MAIN ROAD', 
 'CATEGORY': 'TRANSPORTATION', 
 'TELEPHONE': '_',
 'PINCODE': '_'
}

Similarly, LinString type is stored in the form:

{
'CE_NAME4': '_',
'RD_SURF': '_', 
'ENTRY_BAR': '_',
'PLOTSIZE': '_',
'SRCTYPE': 'Arterial',
'_id': ObjectId('53329164a6e10b0b68bea88f'),
'LM_1': '_',
'ENDPNT_X': 77.707634,
'ENDPNT_Y': 13.020506,
'ONEWAY': '_',
'ROAD_NAME': 'Old Madras Road',
'RD_W_CAT': '_',
'BUSI_4': '_',
'CATEGORY': '1',
'LM_4': '_',
'BUSI_2': '_',
'LENGTH': 675.57,
'LOCALITY': 'Krishnarajpur',
'RH_PLOT2': '_',
'PINCODE': '560036',
'RH_PLOT1': '_',
'AREA': '_',
'COM_SUR': '_',
'LM_3': '_', 
'LH_PLOT1': '_',
'LH_PLOT2': '_',
'STARTPNT_X': 77.702347,
'STARTPNT_Y': 13.017308,
'ID': 1,
'CE_NAME1': '_', 
'CE_NAME2': '_',
'CE_NAME3': '_',
'LM_2': '_', 
'BUSI_3': '_',
'geom': {
         'type': 'LineString',
         'coordinates': [
                         [
                          77.70234680175781,
                          13.017308235168457
                         ],
                         [
                          77.70301055908203,
                          13.017770767211914
                         ],
                        ]
           },
 'BUSI_1': '_'
}

I have created a 2dsphere index as shown:

db.<collection>.ensureIndex({"geom":"2dsphere"})

I ran the following query:

location = db.BLR_all.findOne({ $and: [{"geom.type":"Point"},{"LOCALITY":"KORAMANGALA"}]})
db.runCommand({geoNear: 'BLR_all', near: location.geom, maxDistance: 200, shperical:true})

The purpose of the above query was to retrieve all the geometries that fall with 200m of the 'location'.

Next I want to filter the above query to display only the Point types that fall within the 200m mark of the 'location'. So I included the query field in my runCommand, as shown

db.runCommand({geoNear: 'BLR_all', near: location.geom, maxDistance: 200, query: db.BLR_all.find({"geom.type":"Point"}), shperical:true})

But this returns an empty result.

Is the syntax of the second runCommand statement correct? Kindly provide some simple example if possible on how to apply filters in runCommand.

Thank you.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.