Mongo中的索引创建

时间:2018-04-23 08:02:29

标签: python json mongodb indexing pymongo

我有一个表格中的数据集:

Total

我创建一个查询,返回按MMSI分组并已排序的船舶的位置(坐标)。 COORDINATES:具有相同MMSI的记录数量_id:数组中收集的相同MMSI的坐标和getPositionsOfshipsgrouped = db.samplecol.aggregate([ { "$match": { "properties.MMSI": { "$exists": "true" } } }, { "$project": { "properties.MMSI": "$properties.MMSI", "geometry.coordinates": "$geometry.coordinates" } }, { "$group": { "_id": "$properties.MMSI", "total": { "$sum": 1 }, "COORDINATES": { "$push": "$geometry.coordinates" } } }, { "$match": { "total": { "$gte": 0 } } }, { "$sort": { "total": -1 } }, { "$limit": 15 } ]) :船舶的MMSI。

查询(pymongo):

{
  u'total': 10,
  u'_id': u'503551000',
  u'COORDINATES': [
    [141.8705, -12.67311],
    [158.1707, -0.9142034],
    [157.1707, -0.9142034],
    [157.1707, -0.9142034],
    [157.1707, -0.9142034],
    [157.1707, -0.9142034],
    [159.1707, -0.8142034],
    [158.2707, -0.8142034],
    [159.1707, -0.8142034],
    [159.1707, -0.8142034]
  ]
}

{
  u'total': 2,
  u'_id': u'416243700',
  u'COORDINATES': [
    [159.1707, -0.8142034],
    [159.0707, -0.7142034]
  ]
}

结果:

db.samplecol.ensure_index([("geometry", "2dsphere")])

我认为在这里创建一个好主意的索引。 首先,我在几何中创建地理空间索引:

db.samplecol.ensure_index([
  ("properties.MMSI", 1),
  ("geometry.coordinates", 1),
  ("properties.TIMESTAMP", 1)
])

然后我创建单键索引,如:

select data_Type_Name from data_type where displayName in('groupId','date')

我在索引创建中使用来自$ project的字段(在上面的查询中)。

所以我的问题是,如果这些索引创建将确保更好的性能,并且我使用的字段是否正确。 我有一个小数据集,但我没有在响应时间方面看到更好的表现。

0 个答案:

没有答案
相关问题