简体   繁体   English

猫鼬不查询

[英]Mongoose not querying

I just recently migrated my DB to Atlas.我最近刚刚将我的数据库迁移到 Atlas。 After mongoose.connect I successfully get the promise returned and am connected to my DB.mongoose.connect之后,我成功地得到了返回的承诺并连接到我的数据库。

However, if I do User.find({}).then(users=>{res.json(users)}) I do not get any users returned (empty array) (This all worked prior to migrating)但是,如果我执行User.find({}).then(users=>{res.json(users)})我不会返回任何用户(空数组)(这在迁移之前都有效)

User Schema用户架构

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"))
);

If I query using MongoShell directly如果我直接使用 MongoShell 查询

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

I get the expected results.我得到了预期的结果。 I am not really sure how I should isolate the issue on my local server side.我不太确定应该如何隔离本地服务器端的问题。

I double checked my connection string and that is correct.我仔细检查了我的连接字符串,这是正确的。

I contact Atlas and even though I was connected successfully to my DB the connection string was incorrect.我联系了 Atlas,即使我成功连接到我的数据库,连接字符串也不正确。

Atlas will display the connection string to use, but in fact, it was not the correct one to use. Atlas 将显示要使用的连接字符串,但实际上,它不是正确使用的字符串。 The support team helped me resolve what is actually should be.支持团队帮助我解决了实际应该是什么。 I migrated from mLab and I was still needing to use the name of my mLab DB name.我从 mLab 迁移,但仍然需要使用我的 mLab 数据库名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM