Skip to content Skip to sidebar Skip to footer

Using Mongodb From Client With Javascript

I am trying to use MongoDB with just javascript from client, but MongoDB's documentation on how to achieve this is very confusing. On this webpage there is nothing to download, I w

Solution 1:

The documentation you linked to is about accessing MongoDB with server-sided Javascript using the node.js framework.

MongoDB does offer a REST webservice allowing rudimentary queries through XmlHttpRequests. To enable it, you have to start mongod with the --rest parameter. You can then query it like this:

http://127.0.0.1:28017/yourDatabase/yourCollection/?filter_name=Bob

You can query this URL with an AJAX XmlHttpRequest like any webservice. It will access a database on localhost and return JSON equivalent to a query like this:

yourDatabase.yourCollection.find({name:"Bob"});

This interface, however, is very rudimentary. It only offers simple find queries. But there are 3rd party middleware layers which expose more advanced functionality. This feature and a list of 3rd party solutions is documented here:

http://docs.mongodb.org/ecosystem/tools/http-interfaces/

Solution 2:

Update: MongoDB has a service introduced this year , MongoDB Stitch. This allows developers to connect to MongoDB Atlas (cloud) and expose data as well as queries to be consumed directly at the ui ( through js) . Currently, its in beta but documentation and samples are on their site for reference.

Solution 3:

There are lots of limitations in using REST web services provided by MongoDB. It is having very limited functionality and we can not provide query criteria or sort options while querying the data.

I suggest to write your own server side script or servlet to provide REST interface to fetch the data from MongoDB.

Post a Comment for "Using Mongodb From Client With Javascript"