AntPruve
Connecting Self-Hosted MongoDB to AgGrid Table in Windmill UI - Need Support with Data Display Issue
Script Structure if more context is needed:
import wmill
import pymongo
from typing import Dict
def main(grid_params: Dict = None):
# Get MongoDB connection variables
MONGO_USERNAME = wmill.get_variable("u/pruveadmin/MONGO_USERNAME")
MONGO_PASSWORD = wmill.get_variable("u/pruveadmin/MONGO_PASSWORD")
MONGO_HOST = wmill.get_variable("u/pruveadmin/MONGO_HOST")
MONGO_PORT = wmill.get_variable("u/pruveadmin/MONGO_PORT")
DB_NAME = {redacted for privacy}
mongo_uri = f"mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}@{MONGO_HOST}:{MONGO_PORT}"
# Example showing structure with unique_ID, other fields removed for privacy
projection = {
"_id": 0,
"unique_ID": 1,
# ... other fields
}
try:
client = pymongo.MongoClient(mongo_uri)
db = client[DB_NAME]
collection = db.CD_proc
cursor = collection.find({}, projection).limit(100)
rows = list(cursor)
return {
"columnDefs": [
{"field": "unique_ID", "headerName": "ID", "width": 120},
# ... other columns
],
"rowData": rows,
"lastRow": -1,
"pagination": True,
"rowModelType": "infinite",
"cacheBlockSize": 100,
"paginationPageSize": 100
}
except Exception as e:
return {"error": str(e)}
finally:
if 'client' in locals():
client.close()
AgGrid Configuration:
{
"rowModelType": "infinite",
"cacheBlockSize": 100,
"paginationPageSize": 100,
"rowBuffer": 0,
"getRowId": "params => params.data.unique_ID",
"infiniteInitialRowCount": 1,
"maxBlocksInCache": 2,
"maxConcurrentDatasourceRequests": 2,
"serverSideInfiniteScroll": true,
"pagination": true,
"defaultColDef": {
"filter": true,
"sortable": true,
"resizable": true,
"floatingFilter": true
}
}
8 replies