Faaiz
Faaiz

Reputation: 685

Using Mongo REST API to retrieve json from MongoDB Docker container

I am running the MongoDB on Docker and I want to use Mongo REST API to get the contents of collection. But it's not working for me.

cvedb is the database and cpe is the collection that exist in the database.

Following is the Docker detail:

$ docker ps -a
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                      PORTS                                                      NAMES
2c9b7cbb9346        mongo                         "docker-entrypoint.s…"   16 hours ago        Up 16 hours                 0.0.0.0:27017->27017/tcp, 0.0.0.0:28017->28017/tcp         mongodb

Following is the MongoDB detail

# mongo 
MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e2b36132-09a2-4896-8c8f-795d76458099") }
MongoDB server version: 4.0.10
>

Following is the database and collection detail

> show dbs
admin   0.000GB
config  0.000GB
cvedb   0.394GB
local   0.000GB
> use cvedb
switched to db cvedb
> show collections
capec
cpe
cpeother
cves
cwe
info
mgmt_blacklist
mgmt_whitelist
via4
> 

Following the detail of cpe collection from database.

> use cvedb
switched to db cvedb
> db.cpe.findOne()
{
    "_id" : ObjectId("5a37233cead335ae043608a7"),
    "id" : "cpe:2.3:a:%240.99_kindle_books_project:%240.99_kindle_books:6:-:-:-:-:android",
    "title" : "$0.99 Kindle Books project $0.99 Kindle Books (aka com.kindle.books.for99) for android 6.0",
    "cpe_2_2" : "cpe:/a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~",
    "references" : [
        "https://play.google.com/store/apps/details?id=com.kindle.books.for99",
        "https://docs.google.com/spreadsheets/d/1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/edit?pli=1#gid=1053404143"
    ]
}
>  exit

But, when I do the curl, I get following response.

# curl http://127.0.0.1:28017/cvedb/cpe/
curl: (7) Failed to connect to 127.0.0.1 port 28017: Connection refused

Ideally, in response to curl I should get some response from database collection. What am I missing ?

I did put my question on the MongoDB Slack channel but still did not get any reply.

Upvotes: 0

Views: 2532

Answers (1)

tgogos
tgogos

Reputation: 25240

For this simple HTTP interface, I've seen users running:

  • mongod --httpinterface here
  • mongod --rest here

but they both seem to be deprecated.

Check this: Compatibility Changes in MongoDB 3.6

HTTP Interface and REST API

MongoDB 3.6 removes the deprecated HTTP interface and REST API to MongoDB.

Upvotes: 1

Related Questions