
import motor.motor_asyncio
from bson import ObjectId
from decouple import config

MONGO_ROOT_USER=config('MONGO_ROOT_USER')
MONGO_ROOT_PASSWORD=config('MONGO_ROOT_PASSWORD')
MONGO_URL = f"mongodb://{MONGO_ROOT_USER}:{MONGO_ROOT_PASSWORD}@localhost:27017/"

client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_URL)

database = client.mqtt

mqtt_collection = database.get_collection('mqtt')

def add_mqtt_message(topic, payload):
    mqtt_collection.insert_one({
        'topic': topic,
        'payload': payload,
        '_id': ObjectId()
    })



import motor.motor_asyncio
from bson import ObjectId
from decouple import config

MONGO_ROOT_USER=config('MONGO_ROOT_USER')
MONGO_ROOT_PASSWORD=config('MONGO_ROOT_PASSWORD')
MONGO_URL = f"mongodb://{MONGO_ROOT_USER}:{MONGO_ROOT_PASSWORD}@localhost:27017/"

client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_URL)

database = client.mqtt

mqtt_collection = database.get_collection('mqtt')

def add_mqtt_message(topic, payload):
    mqtt_collection.insert_one({
        'topic': topic,
        'payload': payload,
        '_id': ObjectId()
    })

