9

To connect to a MongoDB database from a NodeJS application, the documentation says to connect an address like this one:

mongodb://localhost:27017/myproject

where mongodb is the protocol, in place of http (or https).

I'm curious how this works though.

When I open my browser, I cannot navigate to this page, and I cannot send requests to it through Postman.

How does this protocol work? How do I manually interact with it? Where can I find more information about it?

10

To manually interact with it you need a client to speak the protocol. This is what a web browser does, it speaks http/https for you and issues commands (GET, POST etc.) and renders the responses for you visually. The default client for manually interacting with MongoDB is the mongo shell - it will connect and speak the MongoDB Wire Protocol for you over TCP/IP and will render the results for you, usually in a text based json format. There are others that will give you a more graphical/visual output, like Robomongo and Mongoclient (for a more complete list the admin UI list).

Within node, this is handled instead by your MongoDB node driver which takes care of speaking the protocol and translating your commands and their corresponding output back and forth into formats that node can use. This is similar to how you would use a http client in node to achieve similar result when querying a web server.

  • Perfect explanation. Could only be improved with a simplification or summary. – 1984 Feb 10 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.