I work locally - it will never be done on a live website. I built a node / express server that will accept a strict aggregation pipeline for Mongo and return the results to the browser:
app.get('/aggregate/:collection', function(req, res) { var queryObject = JSON.parse(req.param('q')); var recProvider = getProviderForTable(req.params.collection); recProvider.getCollection(function(err, collection) { collection.aggregate(queryObject, {}, function(err, data) { res.json(data); }); }); });
This allows you to make quick queries in a browser, where I create a data visualization:
$.get(LOCAL_SERVER + '/aggregate/my_records?q=' + JSON.stringify(pipeline));
I almost started building a query builder like Mongoose, but just to create an array of pipelined aggregates. I am wondering if I can use the Mongoose query builder in the browser only to create an array, and then use it to hit my express server for the data as above?
I want to build a chain object, for example ...
pipeline() .where('value').gt(1000) .where('category').in([1, 2, 3]) .sort('-date') .skip(100).limit(10);
... will return the aggregation pipeline:
[ { $match: { value: { $gt: 1000 }, category: { $in: [1, 2, 3] } } }, { $sort: { date: -1 } }, { $skip: 100, $limit: 10 } ]