5

I am building an ASP.Net web application and want to access data from MongoDB (remotely hosted). Any of my documents looks like this (have ensured index on Utc field);

{ 
   "_id" : { "$oid" : "509501393e8785025c10bc21" }, 
   "Index" : 1,
   "Url" : "http:...", 
   "CameraId" : 123,  
   "Utc" : { "$date" : 1351955858006 } 
}

Considering the performance on user end, I want to fetch this data at max speed. One option that i have tried is calling a local Web Service via JSON on Page.aspx which uses MongoDB C# driver to query documents between two Dates (Utc). That works but seems like using web service adds some extra milliseconds in request/response cycle (request for single document using db.foo.findOne() is served in 1.3 seconds on average). Average number of documents in that collection is 50,000 which will increase up-to 30,00,000.

My questions are:

  1. Am i right in saying that using web services adds some delay (millisecs) in request/response cycle ? (because MongoDB actually takes few milliseconds to complete the query)
  2. Second Option is to use MongoDB's HTTP / REST Interface. That way i might avoid web services and directly query MongoDB. Here i need your opinion on,
    • Is there a way to query MongoDB between two Dates using HTTP/REST ?,
    • Is there a way to query MongoDB with '>' and '<' conditions using HTTP/REST ?,
    • How does it seem, accessing DB directly on Page.aspx with security point of view ?
  3. Any other querying alternative OR optimizations for above schema?

My related question is here.

Regards.

Community
  • 1
  • 1
theGeekster
  • 6,081
  • 12
  • 35
  • 47
  • why would you not use the C# driver for MongoDB and query for data directly? – Asya Kamsky Nov 04 '12 at 05:36
  • As I said earlier, currently i am using C# driver and querying MongoDB directly, but the code using C# driver statements is written in a web method which is called from Page.aspx. I need to know if you have tried MongoDB's HTTP/REST interface and can tell the performance results for comparison with C# driver. – theGeekster Nov 04 '12 at 07:57

1 Answers1

5

MongoDB's native HTTP interface is not built for querying. You should continue to do what you are doing. In addition, your MongoDB servers should not be exposed publicly for security purposes and you should always go through a middle tier as you are currently doing.

Craig Wilson
  • 12,174
  • 3
  • 41
  • 45
  • Still, i wish some REST-based (token-authenticated) way to query MongoDB, like CouchDB. – theGeekster Nov 12 '12 at 04:24
  • 10gen has taken a different point of view. Instead of building a single ubiquitous client for "all languages", it has decided to build specific APIs fore each language/framework so that integration with MongoDB feels natural. That being said, it is possible to build a layer on top of one of these drivers to provide a RESTful interface. For instance, while I don't feel it's ready for production yet, I have implemented an OData provider on top of the .NET driver. OData is a RESTful protocol. https://github.com/craiggwilson/mongo-dotnet-odata – Craig Wilson Nov 12 '12 at 13:34
  • Hmm. Do they have a specific API for curl? Please don't say "The simple REST API" because that is too incomplete and buggy to count. – Max Murphy Jul 06 '15 at 22:27