Mongo shell does not show collections (command show collections) when insert through Node JS

13,064

Maybe you should first pick a db

> show dbs
db1
db2

Then after using a datbase

>use db1

You will see its collections:

>show collections
collection1
collection2

Finally use it:

> db.collection1.find()
Share:
13,064

Related videos on Youtube

webn00b
Author by

webn00b

Updated on June 04, 2022

Comments

  • webn00b
    webn00b almost 2 years

    This is my project url-shortener directory

    I have a Node JS app that involves using MongoDB. It works fine, as I tried inserting, finding, and printing data from MongoDB to the console in the Node JS file, server.js. However, if I open a Mongo Shell and type show collections, it would show nothing.

    Here is how I establish MongoDB connection:

    mongod --dbpath ...path-to-project/url-shortener/data,

    Here is the url I use to connect in my server.js file:

    var dbUrl = "mongodb://localhost:27017/url-shortener";

  • webn00b
    webn00b almost 8 years
    Are you sure show db is a valid command? I get [thread1] Error: don't know how to show [db] :
  • webn00b
    webn00b almost 8 years
    Got it. Thank you. It drove me crazy for the past hour
  • Prathamesh More
    Prathamesh More over 4 years
    Got it! I was doing use collection_name