【问题标题】:Mongo shell does not show collections (command show collections) when insert through Node JS通过Node JS插入时Mongo shell不显示集合(命令显示集合)
【发布时间】:2016-11-27 14:46:54
【问题描述】:

This is my project url-shortener directory

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

这是我建立 MongoDB 连接的方法:

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

这是我在server.js 文件中用来连接的网址:

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

【问题讨论】:

    标签: node.js mongodb shell npm database


    【解决方案1】:

    也许你应该先选择一个数据库

    > show dbs
    db1
    db2
    

    然后在使用数据库之后

    >use db1
    

    你会看到它的收藏:

    >show collections
    collection1
    collection2
    

    终于用上了:

    > db.collection1.find()
    

    【讨论】:

    • 您确定show db 是有效命令吗?我得到[thread1] Error: don't know how to show [db] :
    • 知道了。谢谢你。在过去的一个小时里,它让我发疯了
    • 知道了!我在做use collection_name
    猜你喜欢
    • 2020-03-03
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多