I'm building a JavaFX 2.0 standalone application (it'll be distributed as an .exe) and it opens a connection to a MongoDB instance. The connection is just a standard Mongo connection using the Mongo wire protocol.

Is the Mongo wire protocol secure enough, or could users examine it to see the data being passed back and forth?

Mongo database connections will be able to use SSL at some point in the future, but that isn't available yet.

Instead, should I use a REST web service for data access with SSL? The direct database connection is quite a bit faster so it would be great if I could keep that, but also not have big security problems.

  • 1
    Unless you want to give your end users direct access to the database you need an API in front of mongo anyways. SSL won't protect you from a malicious endpoint. Commented Oct 22, 2013 at 16:41

2 Answers 2


Just for your information. Giving a direct database connection in a client side application is a bad idea. Build a RESTful interface which allows for correct authentication and input validation. This will allow you to have a stricter control on what your applications can access.

The problem is that currently MongoDB doesn't offer SSL encapsulation. This means that in itself, the wire protocol can be eavesdropped upon (the data sent over the protocol is exposed). So if you are running this protocol non-locally (so across a network) then yes it's not secure, but not because the protocol itself is insecure, but because the implementation currently can't guarantee confidentiality or integrity due to the lack of encapsulation.

However you can fix this by encapsulating the protocol yourself. If the protocol doesn't offer SSL you first make a tunnel and send the protocol through that tunnel. For instance you make an encrypted VPN between your webserver and MongoDB and through this VPN you send the wire protocol connection (note that you should use a secure VPN protocol). Preferably this is implemented so that you have end-point encryption.

This will disallow eavesdroppers from sniffing your wire connection.

  • Totally agree with this answer. Just want to reiterate the importance of implementing a RESTful interface. This stands even if in the future Mongo allows SSL connections. SSL only protects the data in transit; a correctly implemented RESTful application will protect against malicious application users.
    – paj28
    Commented Oct 22, 2013 at 17:31
  • I think this answer needs to be revised, as MongoDB now support encryption by TLS.
    – Alireza
    Commented Apr 24, 2018 at 14:02

Mongo database connections will be able to use SSL at some point in the future, but that isn't available yet.

Writing to have a more recent reference for this one.

From https://docs.mongodb.org/manual/tutorial/configure-ssl/

New in version 3.0: Most MongoDB distributions now include support for SSL.


Certain distributions of MongoDB do not contain support for SSL. To use SSL, be sure to choose a package that supports SSL.

You can check if MongoDB for your OS/distribution supports SSL from here.

  • And for those for whom this is not an option, stunnel and stud can wrap the connection easily but best used with persistent connections.
    – symcbean
    Commented Jan 21, 2016 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .