Connecting to mongodb to fetch data

Hi,

I wanted to fetch some data from mongodb while writing tests in postman.
So i wanted to know how to install mongo drivers if necessary, and how to connect to particular db and collection inside that and execute a query to get required data.

I dont know if this kind of thing is supported in postman, if not any other alternative suggestions

Hi @kushal7.bn - You can go through this post which explains on how you can setup a small node server to test your mongoDB database - https://programmerblog.net/nodejs-mongodb-rest-api/

Hi Sivcan, this answer does not fully resolve the original question. The question was how (if possible) to connect to MongoDB directly as part of the pre-request script to get the data in order to validate the API under test, not how to design rest api (but
it is useful article in its own right).

Postman only works with REST APIs as of now and thus it cannot establish a DB connection, so you won’t be able to test it out directly.

Yes you’re correct, thus we didn’t mark the previous reply as a solution to the question because it’s a workaround for someone who wants to test out some flows etc.

Thank you. Would you know if there is any plans to add this feature to the postman. I am currently stuck in the scenario of multiple developers working on the seed data and collections. What I want to do is to create some dynamic validation/selection of the input data before it gets consumed by the end point.

Hi guys, any update on this ? :slight_smile:

Hey @Alex_Tester_CPT :wave:

Welcome to the Postman Community! :postman:

As this is a topic that was raised over 3 years ago, I’m not sure what type of update you were after but all I can tell you is that Postman doesn’t have the functionality to directly connect to a DB via the sandbox environment.

MongoDB uses a proprietary driver for database access, and there (still) isn’t a native http interface.

If you are using a hosted version of MongoDB. Then the following may be an option.

Create A REST API With MongoDB | MongoDB