I have an application built on a proprietary cloud platform, that accesses a MongoDB database (hosted at MongoHQ) via web services.

Since I can not load anything on the proprietary cloud platform, I can not run any native MongoDB driver on the platform. I am forced to use Web Services.

Everything was going swimmingly, until it came time to do basic summary/averages of the data.

Below is an example document, based on mongoDB's posted best practices for time series data. These data points are performance metrics collected within a single hour. (dt = top of the hour, vals are minutes/seconds format (m0214 means 2 minutes 14 seconds past the hour)

{
  _id: ObjectId("531fb241406eb30d07260d61"),
  dt: 1394586000000,
  inst: "my_instance_key",
  vals: {
    m0014: 78,
    m0214: 94,
    m0614: 63,
    m0814: 94,
    m1014: 78,
    m1214: 78,
    m1414: 109,
    m1614: 250,  
    m1814: 78,
    m2014: 125,
    m2214: 94,
    m2414: 63,
    m2614: 78,
    m2814: 63,
    m3014: 78,
    m3214: 78,
    m3414: 63
  }
}

What I want to do is add a summarized "Hourly" value to the document, an average of all the minute values. However there doesn't appear to be a way to do this via a web services call since the aggregation framework seems to be absent from MongoHQ and MongoDBLab's web services API.

I guess my questions are these:

1) Is there a way to do this using published web services API's from MongoHQ or MongoDBLab? (that does not involve downloading all the data points to my app, and doing the math there)

2) Is there any hosted provider of managed MongoDB that allows access to aggregation framework, or provides an elegant way to accomplish this?

Thank you very much for your help!

有帮助吗?

解决方案

Your explanation is not the best for why you are using a Service API as opposed to a driver connection. We can only presume you are using some legacy language such as classic ASP or some other.

If you are using ASP, then using the C# Driver (or really just the .NET driver) may be a possibility for you by following these instructions.

For anything else, I would say that these services are likely to not supply much more than basic CRUD operations. And you are not asking people to recommend are you? because you already know that is "off-topic".

So if you are really in a bind with the language you are working with, then why not create your own RESTFul API? Surely there is another language that you are comfortable in where you could implement this and use the native driver for that language implementation:

An approach like this with nodejs and express might serve as an example:

app.post('/api/db/:varDb/collection/:varCollection/aggregate',
    function(req,res) {

     // Req body has the parsed JSON as the pipeline commands
     // Mongoclient is already open

     var db = mongoclient.db(varDb);

     db.collection(varCollection).aggregate( req.body.pipeline, 
         function(err,response) {

         // Send JSON response to client

     });

});

This would just be a matter of deploying that service somewhere where your legacy code application was able to access it. So yourAPI would now connect to your mongo hosting provider, and your application talks to your API.

These are probably the simplest types of services to build. Go on and try.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top