EVE 中的不同集合

Different collection in EVE

我有一个发送一些信息的蓝牙标签列表。我想为每个 MAC(addr) 标签创建一个集合。我该怎么做?这是我正在使用的设置和我收到的示例 JSON。

DOMAIN = {
'ble': [
    'additional_lookup': {
        'url': 'regex("[\w]+")',
        'field': 'name',
        },
    'schema': {
        'address': {
            'type': 'string'
        },
        'rssi': {
            'type': 'string'
        },
        'name': {
            'type': 'string',
            'unique': True
        },
        'tx_power': {
            'type': 'string'
        },
        'r_time': {
            'type': 'string'
        }
    }
 ]
}

这是我将收到的 JSON 的示例:

[{
    "addr": "ff:ff:00:00:2a:15",
    "datetime": "2016-10-06T05:19:38.+0000",
    "name": "ITAG",
    "rssi": -61,
    "txpw": 0
}, {
    "addr": "66:55:44:33:22:10",
    "datetime": "2016-10-06T05:19:38.+0000",
    "name": "NULL",
    "rssi": -61,
    "txpw": -100
},

{
    "addr": "47:c9:df:25:34:b1",
    "datetime": "2016-10-06T05:19:38.+0000",
    "name": "NULL",
    "rssi": -94,
    "txpw": -100
}
]

我尝试使用 Flask 进行路由,但它没有创建新的集合。这里的代码:

from eve import Eve
import Flask

app = Eve()

@app.route('/ble', methods=['POST'])
def create_ble():
    data = request.get_json()
    json_data = json.loads(data)
    quant = len(json_data['beacon_list'])
    for i in range(0, quant-1):
        beacon = json_data[i]
        addr = json_data[i]['addr']
        beacon = json.dumps(beacon)
        mongo.db[addr].insert(beacon)

    return 


if __name__ == '__main__':
    app.run()

您不需要任何额外的路线。 Eve 支持批量插入。只需 POST 这个 json 到 /ble 端点,但要确保键与您的模式键匹配。