MongoDB教程
本教程演示了如何将app-schema插件与MongoDB数据存储一起使用。本教程将重点介绍MongoDB数据存储的特性,强烈建议您先阅读app-schema文档。
用例
本教程的用例是通过app-schema提供有关存储在MongoDB数据库中的某些气象站的信息。请注意,此用例完全是虚构的,仅用于演示MongoDB和app-schema集成。
首先,让我们在MongoDB数据存储中插入一些测试数据:
db.stations.insert({ "id": "1", "name": "station 1", "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 } ] } ] }) db.stations.insert({ "id": "2", "name": "station 2", "contact": { "mail": "station2@mail.com" }, "geometry": { "coordinates": [ 100, -50 ], "type": "Point" }, "measurements": [ { "name": "temp", "unit": "c", "values": [ { "time": 1482146911, "value": 35 }, { "time": 1482146935, "value": 25 } ] }, { "name": "wind", "unit": "km/h", "values": [ { "time": 1482146964, "value": 80 } ] }, { "name": "pression", "unit": "pa", "values": [ { "time": 1482147026, "value": 1019 }, { "time": 1482147051, "value": 1015 } ] } ] }) db.stations.createIndex({ "geometry": "2dsphere" })
这是将用于在app-schema中执行映射的模式:
<xs:schema version = “1.0” xmlns:xs = “http://www.w3.org/2001/XMLSchema” xmlns:gml = “http://www.opengis.net/gml” xmlns:st = “ http://www.stations.org/1.0“targetNamespace = ”http://www.stations.org/1.0“ elementFormDefault = ”qualified“ attributeFormDefault = ”unqualified“ > <xs:import namespace = ”http:// www .opengis.net / gml“ schemaLocation = ”http://schemas.opengis.net/gml/3.2.1/gml.xsd“ /> <xs:complexType name = ”ContactType“ > <xs:sequence&g