简体   繁体   中英

Mongoose not querying

I just recently migrated my DB to Atlas. After mongoose.connect I successfully get the promise returned and am connected to my DB.

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 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

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 will display the connection string to use, but in fact, it was not the correct one to use. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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