DATABASE

Pymongo rest.py & Studio 3T

ZEROWIN.TECH 2020. 10. 3. 15:55
728x90

Pymongo는 MongoDB 주변의 저수준 Python 래퍼이며 Pymongo로 작업하는 것은 MongoDB 쿼리를 직접 작성하는 것과 유사합니다.

 

1) Pymongo is a low-level Python wrapper around MongoDB, working with Pymongo is similar to writing the

MongoDB query directly.

2) MongoEngine is an Object-Document Mapper, which uses a document schema that makes working with MongoDB clear and easier.

''' -------------- Raspberry Pi (bluetooth)-------------- '''
@app.route("/pi/bluetooth/", methods=['POST'])
def pi_bt():
  dList = request.json
  envList = []
  deList = []
  for data in dList:
    data['GW_DT'] = datetime.datetime.now()
    data['GW_DT_UTC'] = datetime.datetime.utcnow()
    if data['DE_MAC'][0:5] == 'A0:E6':
      envList.append(data)
    else:
      deList.append(data)
  if len(deList) > 0:
  
    DB.CL_DEVICE_DATA.insert(deList)
    
    for data in deList:
        print(data['DE_MAC'])
        print(len(deList))
        
        myquery = { "DE_MAC" : data['DE_MAC'], 'GW_MAC' : data['GW_MAC'] }
        newvalues = { "$set": { "RSSI": data['RSSI'], "GW_DT" : data['GW_DT'], "GW_DT_UTC" : data['GW_DT_UTC'], 'GW_MAC' : data['GW_MAC'] } }
        DB.CL_DEVICE_DATA_2.update(myquery, newvalues, upsert=True)
        
  if len(envList) > 0:
    DB.CL_ENV_DATA.insert(envList)

  return 'OK'

비콘 스캐너로부터 데이터를 수신받아 mongoDB 에 저장합니다.

 

studio3t.com/solutions/

Stduio 3T는 MongoDB GUI 관리툴입니다.

 

Solutions | MongoDB Enterprise Case Studies | Studio 3T

Find enterprise case studies across various industries and learn more about how Studio 3T helps boost MongoDB productivity in companies and teams worldwide.

studio3t.com

Reference

pymongo.readthedocs.io/en/stable/

 

PyMongo 3.11.0 Documentation — PyMongo 3.11.0 documentation

Getting Help If you’re having trouble or have questions about PyMongo, ask your question on our MongoDB Community Forum. You may also want to consider a commercial support subscription. Once you get an answer, it’d be great if you could work it back in

pymongo.readthedocs.io

dev.to/paurakhsharma/flask-rest-api-part-1-using-mongodb-with-flask-3g7d

 

Flask Rest API -Part:1- Using MongoDB with Flask

Part 1: Using MongoDB with Flask Howdy! In the last Part of the series, we learned how to...

dev.to

 

'DATABASE' 카테고리의 다른 글

node-red-node-ui-table 0.3.5  (0) 2020.10.03
Beacon Scanner Test on Node-RED  (0) 2020.09.30
Node-RED on MongoDB  (0) 2020.09.30