Add push.py to post documents to mongo database

This commit is contained in:
Enrique Barcelli 2023-09-14 03:25:27 +08:00
parent 6ece423b43
commit 6acd6c3169
Signed by: kikobar
GPG key ID: 006C13A68E25D3B7
2 changed files with 17 additions and 0 deletions

View file

@ -1,4 +1,6 @@
# MongoDB Database parameters # MongoDB Database parameters
CONNECTION_STRING = "mongodb://user:pass@mongoserver:27017/database" CONNECTION_STRING = "mongodb://user:pass@mongoserver:27017/database"
DATABASE = "uparcel"
COLLECTION = "job-status-log"

15
push.py Normal file
View file

@ -0,0 +1,15 @@
from pymongo import MongoClient
from config import *
import sys
import json
def push(document):
client = MongoClient(CONNECTION_STRING)
database = client[DATABASE]
collection = database[COLLECTION]
collection.insert_one(document)
if __name__ == '__main__':
push(json.loads(sys.argv[1]))