当通过NodeJS插入时,Mongo-shell不显示集合(命令显示集合)



这是我的项目url-shortener目录

我有一个NodeJS应用程序,它涉及到使用MongoDB。当我尝试在NodeJS文件server.JS中将MongoDB中的数据插入、查找和打印到控制台时,它工作得很好。但是,如果我打开MongoShell并键入show collections,它将不会显示任何内容。

以下是我如何建立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()

最新更新