2014-10-10 47 views
0

的名单我有一个集合的MongoDB如下如何ensureIndex几何

{ 
    "_id" : ObjectId(...), 
    "gemetryCollectionId" : 1, 
    "geometry" : [{ 
     "type" : "Polygon", 
     "coordinates" : [[[2, 3], [4, 4], [4, 3], [2, 3]]] 
    }] 
} 

如何确保几何列表索引?

它不工作,如果我这样做

db.collectionName.ensureIndex({"geometry":"2dsphere"}); 
+0

它显示的错误是什么? – 2014-10-10 13:07:57

回答

0

你给几何形状的阵列。尝试通过仅将其创建为对象来创建索引。像这样:

{ 
    "_id" : ObjectId(...), 
    "gemetryCollectionId" : 1, 
    "geometry" : { 
     "type" : "Polygon", 
     "coordinates" : [[[2, 3], [4, 4], [4, 3], [2, 3]]] 
    } 
} 

它会工作。

谢谢