【问题标题】:Mongoose not querying猫鼬不查询
【发布时间】:2020-06-02 18:29:19
【问题描述】:

我最近刚刚将我的数据库迁移到 Atlas。在mongoose.connect 之后,我成功地得到了返回的承诺并连接到我的数据库。

但是,如果我这样做 User.find({}).then(users=>{res.json(users)}) 我不会返回任何用户(空数组)(这一切在迁移之前都有效)

用户架构

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// Create Schema
const UserSchema = new Schema({
  email: {
    type: String
  }
});

module.exports = User = mongoose.model(
  "User",
  UserSchema.plugin(require("mongoose-autopopulate"))
);

如果我直接使用 MongoShell 进行查询

db.getCollection("users").find({})

我得到了预期的结果。我不确定如何在本地服务器端隔离问题。

我仔细检查了我的连接字符串,这是正确的。

【问题讨论】:

    标签: node.js mongodb mongoose mongodb-atlas


    【解决方案1】:

    我联系了 Atlas,即使我成功连接到我的数据库,连接字符串也不正确。

    Atlas 将显示要使用的连接字符串,但实际上它不是正确的。支持团队帮助我解决了实际情况。我从 mLab 迁移,我仍然需要使用我的 mLab 数据库名称。

    【讨论】:

      猜你喜欢
      • 2016-01-10
      • 1970-01-01
      • 2012-02-03
      • 2018-03-07
      • 1970-01-01
      • 2021-03-23
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多