Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access MongoDB directly via JavaScript

is there any possibility to access and retrieve data from MongoDB directly over JavaScript form browser without backend processing?

like image 493
haki Avatar asked Jan 25 '10 15:01

haki


2 Answers

MongoDB natively does not have a fully usable REST interface. You will need either Python based Sleepy Mongoose or Node.js based MongoDB Rest

Please see http://www.mongodb.org/display/DOCS/Http+Interface for more information.

Mongo's inbuilt REST interface is very basic & read only.

like image 129
Mayank Jain Avatar answered Sep 24 '22 00:09

Mayank Jain


If you happen to host your database on MongoLabs, they also expose a REST API. Watch out, it's not secure, as an API key is passed with each request, but your could use it to retrieve public data through Javascript:

https://support.mongolab.com/entries/20433053-Is-there-a-REST-API-for-MongoDB-

Once you have your mongolab db setup, you can access it thru REST request such as

$.getJSON("https://api.mongolab.com/api/1/databases/your-db/collections/your-collection/?apiKey=your-key", function(json) {   //console.log( "JSON Data: " + json ); }); 
like image 31
Rima Avatar answered Sep 24 '22 00:09

Rima