node.js - 通过 Node JS 插入时,Mongo shell 不显示集合(命令 show collections)

标签 node.js mongodb shell npm database

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/

相关文章:

mongodb - 使用pymongo修复mongodb数据库

bash - 获取 STDOUT 第 n 行的命令

regex - BASH shell 使用正则表达式从文件中获取值到参数中

node.js - 如何从 mongoDB 获取多个文档?

mongodb - 如何在 sails js 框架中执行不区分大小写的排序?

Linux shell 脚本到 tar.gzip 日志文件超过 1 个月按月分组

testing - nodejs,文件更改时自动运行测试

node.js - 检测 Google Chrome 页面预取

javascript - 如何返回 Azure 函数的结果

linux - 关闭终端后的网络服务器