如何在mongodb中创建2dsphere索引
我有样品如何在mongodb中创建2dsphere索引,mongodb,mongodb-query,Mongodb,Mongodb Query,我有样品收集 { "_id" : ObjectId("5936986f6b5f90330f8e34ba"), "factual_id" : "7b758ba0-1e18-012f-0643-0030487f54d8", "name" : "Buckhorn Bar", "address" : "105 S MAIN St", "address_extended" : null, "po_box" : "P.O. Box 115", "loc
收集
{
"_id" : ObjectId("5936986f6b5f90330f8e34ba"),
"factual_id" : "7b758ba0-1e18-012f-0643-0030487f54d8",
"name" : "Buckhorn Bar",
"address" : "105 S MAIN St",
"address_extended" : null,
"po_box" : "P.O. Box 115",
"locality" : "Viborg",
"region" : "SD",
"post_town" : null,
"admin_region" : null,
"postcode" : NumberLong("57070"),
"country" : "us",
"tel" : "(605) 766-0086",
"fax" : null,
"latitude" : 43.170177,
"longitude" : -97.081538,
"neighborhood" : null,
"website" : null,
"email" : null,
"category_ids" : [
NumberLong("347"),
NumberLong("312")
],
"category_labels" : [
[
"Social",
"Food and Dining",
"Restaurants"
],
[
"Social",
"Bars"
]
],
"chain_name" : null,
"chain_id" : null,
"hours" : null,
"hours_display" : null,
"existence" : 0.7,
"cuisine" : [
"Pub Food"
],
"price" : NumberLong("1"),
"rating" : null,
"payment_cashonly" : null,
"reservations" : null,
"open_24hrs" : null,
"founded" : null,
"attire" : null,
"attire_required" : null,
"attire_prohibited" : null,
"parking" : null,
"parking_valet" : null,
"parking_garage" : null,
"parking_street" : null,
"parking_lot" : null,
"parking_validated" : null,
"parking_free" : null,
"smoking" : null,
"meal_breakfast" : true,
"meal_lunch" : true,
"meal_dinner" : null,
"meal_deliver" : null,
"meal_takeout" : null,
"meal_cater" : null,
"alcohol" : true,
"alcohol_bar" : true,
"alcohol_beer_wine" : true,
"alcohol_byob" : null,
"kids_goodfor" : null,
"kids_menu" : null,
"groups_goodfor" : null,
"accessible_wheelchair" : null,
"seating_outdoor" : null,
"wifi" : null,
"owner" : null,
"room_private" : null,
"options_vegetarian" : null,
"options_vegan" : null,
"options_glutenfree" : null,
"options_lowfat" : null,
"options_organic" : null,
"options_healthy" : null,
"loc" : {
"type" : "Point",
"coordinates " : [
-97.081538,
43.170177
]
}
},
/* 2 createdAt:6/6/2017, 5:26:31 PM*/
{
"_id" : ObjectId("5936986f6b5f90330f8e34bb"),
"factual_id" : "7b8a33b9-9ca9-4068-b711-012a77d016a4",
"name" : "Retro Bean",
"address" : "10606 Sales Rd S",
"address_extended" : null,
"po_box" : null,
"locality" : "Tacoma",
"region" : "WA",
"post_town" : null,
"admin_region" : null,
"postcode" : NumberLong("98444"),
"country" : "us",
"tel" : "(253) 267-0272",
"fax" : null,
"latitude" : 47.160925,
"longitude" : -122.46548,
"neighborhood" : null,
"website" : null,
"email" : null,
"category_ids" : [
NumberLong("342")
],
"category_labels" : [
[
"Social",
"Food and Dining",
"Cafes, Coffee and Tea Houses"
]
],
"chain_name" : null,
"chain_id" : null,
"hours" : {
"sunday" : [
[
"7:00",
"16:00"
]
],
"saturday" : [
[
"6:00",
"17:00"
]
],
"tuesday" : [
[
"5:00",
"17:30"
]
],
"friday" : [
[
"5:00",
"17:30"
]
],
"thursday" : [
[
"5:00",
"17:30"
]
],
"wednesday" : [
[
"5:00",
"17:30"
]
],
"monday" : [
[
"5:00",
"17:30"
]
]
},
"hours_display" : "Mon-Fri 5:00 AM-5:30 PM; Sat 6:00 AM-5:00 PM; Sun 7:00 AM-4:00 PM",
"existence" : 0.7,
"cuisine" : null,
"price" : null,
"rating" : null,
"payment_cashonly" : null,
"reservations" : null,
"open_24hrs" : null,
"founded" : null,
"attire" : null,
"attire_required" : null,
"attire_prohibited" : null,
"parking" : null,
"parking_valet" : null,
"parking_garage" : null,
"parking_street" : null,
"parking_lot" : null,
"parking_validated" : null,
"parking_free" : null,
"smoking" : null,
"meal_breakfast" : null,
"meal_lunch" : null,
"meal_dinner" : null,
"meal_deliver" : null,
"meal_takeout" : null,
"meal_cater" : null,
"alcohol" : null,
"alcohol_bar" : null,
"alcohol_beer_wine" : null,
"alcohol_byob" : null,
"kids_goodfor" : null,
"kids_menu" : null,
"groups_goodfor" : null,
"accessible_wheelchair" : null,
"seating_outdoor" : null,
"wifi" : null,
"owner" : null,
"room_private" : null,
"options_vegetarian" : null,
"options_vegan" : null,
"options_glutenfree" : null,
"options_lowfat" : null,
"options_organic" : null,
"options_healthy" : null,
"loc" : {
"type" : "Point",
"coordinates " : [
-122.46548,
47.160925
]
}
}
现在,我正试图在loc
字段上使用
db.restaurant.ensureIndex({
loc : "2dsphere"
});
我也试过了
db.restaurant.createIndex( { "loc" : "2dsphere" } )
但在这两种情况下,我都得到了错误“点必须是数组或对象”
{
“消息”:“无法提取地理密钥:{u id:ObjectId('5936986f6b5f90330f8e34ba'),事实id:'7b758ba0-1e18-012f-0643-0030487f54d8',名称:'Buckhorn Bar',地址:'105 S MAIN St',地址扩展:null,邮政信箱:'P.O.box 115',地址:'Viborg',地区:'SD',邮政城镇:null,管理地区:null,邮编:5707070,国家:'S',电话:'(605)766-0086',传真:空,纬度:43.170177,经度:-97.081537999999,邻居:空,网站:空,电子邮件:空,类别id:[347312],类别标签:[[“社交”,“食品和餐饮”,“餐厅],[“社交”,“酒吧]],连锁店名称:空,连锁店id:空,小时:空,小时显示:空,存在:0.7,美食:[“酒吧食品”],价格:1,等级:空,付款:空,预订:空,开放24小时:空,成立:空,服装:空,服装要求:空,服装禁止:空,停车:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,免费:空,吸烟:空,用餐/早餐:真,mea午餐:真,晚餐:空,餐点:空,外卖:空,餐饮:空,酒精:真,酒精酒吧:真,酒精啤酒酒:真,酒精饮料:空,儿童食品:空,儿童菜单:空,团体食品:空,无障碍轮椅:空,户外座位:空,无线网络:空,所有者:空,房间私人:空,选项:素食:null,options_vegan:null,options_lumnfree:null,options_lowfat:null,options_organic:null,options_health:null,loc:{type:'Point',坐标:[-97.081537999999,43.170177]}点必须是数组或对象“,
“堆栈”:“MongoError:无法提取地理键:{u id:ObjectId('5936986f6b5f90330f8e34ba'),事实id:'7b758ba0-1e18-012f-0643-0030487f54d8',名称:'Buckhorn Bar',地址:'105 S MAIN St',地址扩展:null,邮政信箱:'P.O.box 115',地址:'Viborg',地区:'SD',邮政城镇:null,行政地区:null,邮编:57070,国家:'us',电话:'(605)766-0086',传真:空,纬度:43.170177,经度:-97.081537999999,邻里:空,网站:空,电子邮件:空,分类id:[347312],分类标签:[[社交”,“食品和餐饮”,“餐厅],[社交”,“酒吧]],连锁店名称:空,连锁店id:空,小时:空,小时显示:空,存在:0.7,烹饪:[“酒吧食品”],价格:1,等级:空,付款:空,预订:空,开放24小时:空,成立:空,服装:空,服装要求:空,服装禁止:空,停车:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,免费:空,吸烟:空,用餐/早餐:真,mea午餐:真,晚餐:空,餐点:空,外卖:空,餐饮:空,酒精:真,酒精酒吧:真,酒精啤酒酒:真,酒精饮料:空,儿童食品:空,儿童菜单:空,团体食品:空,无障碍轮椅:空,户外座位:空,无线网络:空,所有者:空,房间私人:空,选项:素食:null,options_vegan:null,options_lumnfree:null,options_lowfat:null,options_organic:null,options_health:null,loc:{type:'Point',坐标:[-97.081537999999,43.170177]}点必须是数组或对象“+
“在Function.MongoError.create(C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node\u modules\\mongodb core\\lib\\error.js:31:11)”+
“在C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node\u modules\\mongodb core\\lib\\connection\\pool.js:497:72”+
“在AuthenticateTraggler(C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node\U modules\\mongodb core\\lib\\connection\\pool.js:443:16)”+
“在Connection.messageHandler(C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node\u modules\\mongodb core\\lib\\Connection\\pool.js:477:5)”+
“在套接字上。(C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node\u modules\\mongodb core\\lib\\connection\\connection.js:240:18)”+
“在emitOne(events.js:96:13)”+
“在Socket.emit上(events.js:188:7)”+
“在readableAddChunk(_stream_readable.js:176:18)”+
“位于Socket.Readable.push(_stream_Readable.js:134:10)”+
“在TCP.onread(net.js:551:20)”中,
“名称”:“MongoError”,
“ok”:0,
“errmsg”:“无法提取地理键:{u id:ObjectId('5936986f6b5f90330f8e34ba'),事实id:'7b758ba0-1e18-012f-0643-0030487f54d8',名称:'Buckhorn Bar',地址:'105 S MAIN St',地址扩展:null,邮政信箱:115',地址:'Viborg',地区:'SD',邮政城镇:null,行政地区:null,邮编:5707070,国家:'us',电话:'(605)766-0086',传真:空,纬度:43.170177,经度:-97.081537999999,邻居:空,网站:空,电子邮件:空,类别id:[347312],类别标签:[[“社交”,“食品和餐饮”,“餐厅],[“社交”,“酒吧]],连锁店名称:空,连锁店id:空,小时:空,小时显示:空,存在:0.7,美食:[“酒吧食品”],价格:1,等级:空,付款:空,预订:空,开放24小时:空,成立:空,服装:空,服装要求:空,服装禁止:空,停车:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,停车场:空,免费:空,吸烟:空,用餐/早餐:真,mea午餐:对,晚餐:对,送餐:对,外卖:对,餐饮:对,酒精:对,酒精酒吧:对,酒精啤酒酒:
{
"message" : "Can't extract geo keys: { _id: ObjectId('5936986f6b5f90330f8e34ba'), factual_id: '7b758ba0-1e18-012f-0643-0030487f54d8', name: 'Buckhorn Bar', address: '105 S MAIN St', address_extended: null, po_box: 'P.O. Box 115', locality: 'Viborg', region: 'SD', post_town: null, admin_region: null, postcode: 57070, country: 'us', tel: '(605) 766-0086', fax: null, latitude: 43.170177, longitude: -97.08153799999999, neighborhood: null, website: null, email: null, category_ids: [ 347, 312 ], category_labels: [ [ 'Social', 'Food and Dining', 'Restaurants' ], [ 'Social', 'Bars' ] ], chain_name: null, chain_id: null, hours: null, hours_display: null, existence: 0.7, cuisine: [ 'Pub Food' ], price: 1, rating: null, payment_cashonly: null, reservations: null, open_24hrs: null, founded: null, attire: null, attire_required: null, attire_prohibited: null, parking: null, parking_valet: null, parking_garage: null, parking_street: null, parking_lot: null, parking_validated: null, parking_free: null, smoking: null, meal_breakfast: true, meal_lunch: true, meal_dinner: null, meal_deliver: null, meal_takeout: null, meal_cater: null, alcohol: true, alcohol_bar: true, alcohol_beer_wine: true, alcohol_byob: null, kids_goodfor: null, kids_menu: null, groups_goodfor: null, accessible_wheelchair: null, seating_outdoor: null, wifi: null, owner: null, room_private: null, options_vegetarian: null, options_vegan: null, options_glutenfree: null, options_lowfat: null, options_organic: null, options_healthy: null, loc: { type: 'Point', coordinates : [ -97.08153799999999, 43.170177 ] } } Point must be an array or object",
"stack" : "MongoError: Can't extract geo keys: { _id: ObjectId('5936986f6b5f90330f8e34ba'), factual_id: '7b758ba0-1e18-012f-0643-0030487f54d8', name: 'Buckhorn Bar', address: '105 S MAIN St', address_extended: null, po_box: 'P.O. Box 115', locality: 'Viborg', region: 'SD', post_town: null, admin_region: null, postcode: 57070, country: 'us', tel: '(605) 766-0086', fax: null, latitude: 43.170177, longitude: -97.08153799999999, neighborhood: null, website: null, email: null, category_ids: [ 347, 312 ], category_labels: [ [ 'Social', 'Food and Dining', 'Restaurants' ], [ 'Social', 'Bars' ] ], chain_name: null, chain_id: null, hours: null, hours_display: null, existence: 0.7, cuisine: [ 'Pub Food' ], price: 1, rating: null, payment_cashonly: null, reservations: null, open_24hrs: null, founded: null, attire: null, attire_required: null, attire_prohibited: null, parking: null, parking_valet: null, parking_garage: null, parking_street: null, parking_lot: null, parking_validated: null, parking_free: null, smoking: null, meal_breakfast: true, meal_lunch: true, meal_dinner: null, meal_deliver: null, meal_takeout: null, meal_cater: null, alcohol: true, alcohol_bar: true, alcohol_beer_wine: true, alcohol_byob: null, kids_goodfor: null, kids_menu: null, groups_goodfor: null, accessible_wheelchair: null, seating_outdoor: null, wifi: null, owner: null, room_private: null, options_vegetarian: null, options_vegan: null, options_glutenfree: null, options_lowfat: null, options_organic: null, options_healthy: null, loc: { type: 'Point', coordinates : [ -97.08153799999999, 43.170177 ] } } Point must be an array or object" +
"at Function.MongoError.create (C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node_modules\\mongodb-core\\lib\\error.js:31:11)" +
"at C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node_modules\\mongodb-core\\lib\\connection\\pool.js:497:72" +
"at authenticateStragglers (C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node_modules\\mongodb-core\\lib\\connection\\pool.js:443:16)" +
"at Connection.messageHandler (C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node_modules\\mongodb-core\\lib\\connection\\pool.js:477:5)" +
"at Socket.<anonymous> (C:\\Users\\aman.maurya\\AppData\\Local\\mongobooster\\app-3.5.6\\resources\\app.asar\\node_modules\\mongodb-core\\lib\\connection\\connection.js:240:18)" +
"at emitOne (events.js:96:13)" +
"at Socket.emit (events.js:188:7)" +
"at readableAddChunk (_stream_readable.js:176:18)" +
"at Socket.Readable.push (_stream_readable.js:134:10)" +
"at TCP.onread (net.js:551:20)",
"name" : "MongoError",
"ok" : 0,
"errmsg" : "Can't extract geo keys: { _id: ObjectId('5936986f6b5f90330f8e34ba'), factual_id: '7b758ba0-1e18-012f-0643-0030487f54d8', name: 'Buckhorn Bar', address: '105 S MAIN St', address_extended: null, po_box: 'P.O. Box 115', locality: 'Viborg', region: 'SD', post_town: null, admin_region: null, postcode: 57070, country: 'us', tel: '(605) 766-0086', fax: null, latitude: 43.170177, longitude: -97.08153799999999, neighborhood: null, website: null, email: null, category_ids: [ 347, 312 ], category_labels: [ [ 'Social', 'Food and Dining', 'Restaurants' ], [ 'Social', 'Bars' ] ], chain_name: null, chain_id: null, hours: null, hours_display: null, existence: 0.7, cuisine: [ 'Pub Food' ], price: 1, rating: null, payment_cashonly: null, reservations: null, open_24hrs: null, founded: null, attire: null, attire_required: null, attire_prohibited: null, parking: null, parking_valet: null, parking_garage: null, parking_street: null, parking_lot: null, parking_validated: null, parking_free: null, smoking: null, meal_breakfast: true, meal_lunch: true, meal_dinner: null, meal_deliver: null, meal_takeout: null, meal_cater: null, alcohol: true, alcohol_bar: true, alcohol_beer_wine: true, alcohol_byob: null, kids_goodfor: null, kids_menu: null, groups_goodfor: null, accessible_wheelchair: null, seating_outdoor: null, wifi: null, owner: null, room_private: null, options_vegetarian: null, options_vegan: null, options_glutenfree: null, options_lowfat: null, options_organic: null, options_healthy: null, loc: { type: 'Point', coordinates : [ -97.08153799999999, 43.170177 ] } } Point must be an array or object",
"code" : 16755
}