Check if ID exists in a collection with mongoose

前端 未结 5 975
無奈伤痛
無奈伤痛 2021-01-31 15:52

For instance, I have a collection User:

var mongoose = require(\'mongoose\');

var UserSchema = new mongoose.Schema({
    email: String,
    googleI         


        
5条回答
  •  情深已故
    2021-01-31 16:47

    User.exists({ _id: userID }).then(exists => {
      if (exists) {
        res.redirect('/dashboard')
      } else {
        res.redirect('/login')
      }
    })
    

    More info can be found at Mongoose docs.

提交回复
热议问题