Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying MongoDB with JSON / HTTP / REST Interface

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.

like image 389
theGeekster Avatar asked Nov 04 '12 05:11

theGeekster


People also ask

How do I access the HTTP interface of MongoDB?

To access the http interface an administrator may, for example, point a browser to http://localhost:28017 if mongod is running with the default port on the local machine.

Does MongoDB support REST API?

Atlas Data API is a fully managed REST-like API, to allow you to access your MongoDB Atlas data, and perform CRUD operations and aggregations with ease. Once enabled on a cluster, you can achieve all the CRUD operations out of the box via a URL, with just an API key.

Does MongoDB use API?

The MongoDB Atlas Data API lets you read and write data in Atlas with standard HTTPS requests. To use the Data API, all you need is an HTTPS client and a valid API key. Clients send requests to specific endpoints, which each represent a MongoDB operation.

How do I request data from MongoDB?

You can use read operations to retrieve data from your MongoDB database. There are multiple types of read operations that access the data in different ways. If you want to request results based on a set of criteria from the existing set of data, you can use a find operation such as the find() or findOne() methods.


1 Answers

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.

like image 189
Craig Wilson Avatar answered Oct 27 '22 00:10

Craig Wilson