MongoDB无模式支持

通过单击MongoDB模式,我们将进入存储配置页面。唯一需要的参数是 workspace 以及 MongoDBURI 。有关可用的MongoDB URI格式的描述,请查看 here

../../../_images/schemaless-mongo-configuration-page.png

保存后,可以通过层配置页面将数据库中找到的每个MongoDB集合作为层提供服务。

可以通过在MongoDB集合中所需的几何属性上设置几何索引来定义默认几何。

作为获得的输出的一个例子,我们将使用站点用例。在MongoDB集合中,我们提供了以下文档和其他文档:

  {
 "_id": {
   "$oid": "58e5889ce4b02461ad5af080"
 },
 "id": "1",
 "name": "station 1",
 "numericValue": 20,
 "contact": {
   "mail": "station1@mail.com"
 },
 "geometry": {
   "coordinates": [
     50,
     60
   ],
   "type": "Point"
 },
 "measurements": [
   {
     "name": "temp",
     "unit": "c",
     "values": [
       {
         "time": 1482146800,
         "value": 20
       }
     ]
   },
   {
     "name": "wind",
     "unit": "km/h",
     "values": [
       {
         "time": 1482146833,
         "value": 155
       }
     ]
   }
 ]
}

该特定文档的GeoJSON输出将是以下功能:

{
 "type": "Feature",
 "id": "58e5889ce4b02461ad5af080",
 "geometry": {
   "type": "Point",
   "coordinates": [
     50,
     60
   ]
 },
 "properties": {
   "@featureType": "stations",
   "_id": "58e5889ce4b02461ad5af080",
   "name": "station 1",
   "numericValue": 20,
   "contact": {
     "type": "Feature",
     "id": "fid-3087ff95_17844d87c61_-7aad",
     "geometry": null,
     "properties": {
       "@featureType": "Contact",
       "mail": "station1@mail.com"
     }
   },
   "id": "1",
   "measurements": [
     {
       "values": [
         {
           "value": 20,
           "time": 1482146800
         }
       ],
       "name": "temp",
       "unit": "c"
     },
     {
       "values": [
         {
           "value": 155,
           "time": 1482146833
         }
       ],
       "name": "wind",
       "unit": "km/h"
     }
   ]
  }
}

可以看到,Feature对象非常接近相应MongoDB文档的外观。

简化的属性访问

在幕后,该模块动态地自动构建复杂的功能模式,同时提供复杂的功能。文档中的每个数组或对象都被视为嵌套特征。由于内部嵌套的特征表示遵循GML对象属性模型,这可能导致很难预测访问特征属性以实现样式或过滤目的所需的XPath。

为了澄清这一点,让我们假设我们想要根据大于100的测量值来过滤站点要素。根据上面的GeoJSON特征表示,整个过滤器将如下所示: measurements.MeasurementsFeature.values.ValuesFeature.value > 100

属性路径需要为每个嵌套的复杂属性指定属性名称和功能名称。前者与文档中的原始属性名称重合,而后者的属性名称首字母大小写, Feature 后缀。

为了避免用户需要处理这种复杂性,实现了简化的属性访问支持。这允许引用路径与GeoJSON输出格式或文档结构匹配的属性。

那么先前定义的筛选器可以是: measurements.values.value > 100

可以看到,从GeoJSON输出和MongoDB文档都可以很容易地推断出属性路径。