Search code examples
mongodbwindows-server-2016

How do I access MongoDB data?


I'm moving a website and Mongo database to a new server.
Website can't see the data.
Mongo is installed and running on the same server.
Shell and server are both 3.6.3

Mongo shell sees the database.
From the shell,

dbs returns the database name.
use dbname appears to work.
db.getCollectionNames() returns a reasonable collection name. Say ["myCollection"]

.

db.getCollection("myColection").getIndexes() returns
[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "id", "ns" : "myDB.myCollection" } ]

But after that, I can't get any further.

db.myCollection.find() and
db.getCollection("myCollection").find() both return nothing.

Everything in the log looks correct, no errors.

Does that tell us anything?


Solution

  • One of the features of Mongo is that you can create a database or collection just by mentioning it.
    Turns out that someone had tried to import the data and failed. So when I looked at 'show dbs' and 'getCollectionNames', it looked like it was working.
    The files I saw in the database directory were export files that hadn't actually been imported.