mongo-express-docker icon indicating copy to clipboard operation
mongo-express-docker copied to clipboard

Db not found in mongo express, which is connected with my node application

Open ajaythakor opened this issue 4 years ago • 4 comments

I have created an image with Docker for mongo db named mongodb and I am running mongo express using this mongodb.

image

Here's my code of app.js

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = 'mongodb://127.0.0.1:27017';

// Database Name
const dbName = 'abstractdb'; //''myproject';

// Use connect method to connect to the server
MongoClient.connect(url, function (err, client) {

    assert.equal(null, err);
    console.log("Connected successfully to server.");

    const db = client.db(dbName);
    // insertDocuments(db, function () {
    //     client.close();
    // });

     insertDocuments(db, function () {
        findDocuments(db, function () {
            client.close();
        });
     });

});

const insertDocuments = function (db, callback) {
    // Get the documents collection
    const collection = db.collection('documents');
    // Insert some documents
    debugger;
    collection.insertMany([
        { a: 4 }, { a: 5 }, { a: 6 }
    ], function (err, result) {
        
        debugger;

        assert.equal(err, null);
        assert.equal(3, result.result.n);
        assert.equal(3, result.ops.length);

        debugger;

        console.log("Inserted 3 documents into the collection");
        callback(result);
    });
}

const findDocuments = function (db, callback) {
    // Get the documents collection
    const collection = db.collection('documents') //('abstract');
    // Find some documents`
    debugger;
    collection.find({}).toArray(function (err, docs) {
        assert.equal(err, null);
        debugger;
        console.log("Found the following records");
        console.log(docs)
        callback(docs);
    });
}

Whenever I run my project using the command node app.js, it inserts the data and retrieves it as shown in below image:

image

However, when I check it in browser http://localhost:8081/, I can not see this newly added data, and I can not even see the database/collection created. It just shows the default admin, config and local.

image

The package config contains "mongodb": "^3.5.9".

I have also tried by changing the container name to localmongo, but nothing worked. Please help me in this.

ajaythakor avatar Jul 27 '20 05:07 ajaythakor

I also have the same problem.

I found an article on StackOverflow that says it is necessary to run the mongo-express with the '-a' flag but I don't know how to do this in the container.

https://stackoverflow.com/questions/43695158/mongo-express-not-showing-all-dbs-with-root-admin/43695381

henriquegranatto avatar Mar 29 '21 23:03 henriquegranatto

I've been running into this issue too, strangely it came from an official image of Mongo. Even using the default configurations of Docker compose still did not resolve the problem.

Hopefully, there will be progress on this issue or a friendly guide to start with.

zaimazhar avatar Aug 03 '21 04:08 zaimazhar

I have the same problem, has anyone found a solution?

rafael-tec avatar Jul 04 '23 11:07 rafael-tec