example Using MongoDB from client with Javascript

mongodb example (4)

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:

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:


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:


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 was expecting to see something like mongo.js.

Here I did find mongo.js, and using this I am trying to make it work but with no luck.

The Javascript console in Google Chrome is saying:

Uncaught TypeError: Object [object Object] has no method 'init'

In this snippet from mongo.js:

if ( typeof Mongo == "undefined" ){
  Mongo = function( host ){
    this.init( host );  

Does anyone have any tips on using MongoDB with pure Javascript?

Answer #1

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.

Answer #2

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.