私は私の文書だけがあるデータベースを持っていますPoints
。地理空間インデックスを追加することを検討しています。したがって、2dsphereと2dsphereのどちらかを選択できます。
MongoDB.org には次のものがあります。
2dsphere インデックスのサポート:
- Calculations on a sphere
- Both GeoJSON objects and legacy coordinate pairs
- A compound index with scalar index fields (i.e. ascending or
descending) as a prefix or suffix of the 2dsphere index field
2d インデックスのサポート:
- Calculations using flat geometry
- Legacy coordinate pairs (i.e., geospatial points on a flat
coordinate system)
- A compound index with only one additional field, as a suffix of
the 2d index field
ただし、私のドキュメントはすべてポイントであるため、スキーマに以下のオプションのいずれかを含めることができますが、大きな違いはありません。
2dsphere の場合:
location : {
type : "Point" ,
coordinates : [10,45]
}
または 2 次元インデックスの場合:
location : [10,45]
私の質問はどちらが速いですか? どうやって測ればいいのか、まったくわかりません。
質問は、データの正方形をクエリしたいだけでbox
、複雑なポリゴン検索を気にしないことを前提としています: 2d インデックスでのみサポートされている$boxを使用するか (正しく読み取った場合)、または$geoWithi nの$polygonメソッドを使用します両方のインデックスでサポートされています。