当通过节点JS插入时,Mongo shell不显示集合(命令显示集合)

这是我的项目url-shortener目录

我有一个涉及使用MongoDB的Node JS应用程序。 它工作正常,因为我尝试插入,查找和打印数据从MongoDB到节点JS文件server.js中的控制台。 但是,如果我打开一个Mongo Shell并键入show collections ,则什么也不显示。

以下是我如何build立MongoDB连接:

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

这里是我用来连接我的server.js文件的url:

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

也许你应该先挑一个分贝

 > show dbs db1 db2 

然后在使用数据库之后

 >use db1 

你会看到它的集合:

 >show collections collection1 collection2 

最后使用它:

 > db.collection1.find()