This is my project url-shortener
directory
我有一个涉及使用 MongoDB 的 Node JS 应用程序。它工作正常,因为我尝试从 MongoDB 插入、查找和打印数据到 Node JS 文件 server.js 中的控制台。但是,如果我打开 Mongo Shell 并键入 show collections
,它什么也不会显示。
下面是我如何建立 MongoDB 连接:
mongod --dbpath ...路径到项目/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()
关于node.js - 通过 Node JS 插入时,Mongo shell 不显示集合(命令 show collections),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38547766/