php - MongoDB server-side aggregate queries shared between multiple scripts -
we have mongodb database pull data different sources, using aggregate framework.
a python script generates pdf reports, our dashboard plots graphs of data pulled php backend. these scripts use same aggregate pipelines, code replicated in python , php.
we make queries framework-independent, because plan move backend php python, , in general avoid code replication.
i thought 1 solution have queries in js file, or somehow store them (on mongo) server side, i'm not sure whether possible or not.
for refer mysql, want mysql views on mongodb. suggestion?
edit1:
i'm experimenting server-side javascript doesn't seem option apparently allows $where
, ``mapreduce``` operations. loading external javascript may option too.
i'd recommend storing aggregation pipelines in json files , loading them scripts. e.g. in python:
import json import pymongo pipeline = json.load(open('filename.json')) collection = pymongo.mongoclient().db.collection doc in collection.aggregate(pipeline): print(doc)
Comments
Post a Comment