Monday 29 May 2017

Define two findOne on one method

I have error when i define findOne using mongoose like this,

Nodes.findOne({label: req.decoded.username}, function(err, node){
      Skema.findOne({_id: node.user}, function(err, user) {
          if (req.body.topic == user.username+'/'+node.label) {
            res.sendStatus(200)
          } else{
            res.sendStatus(403)
          }
      })
    })

My mongoose scheme,

var userscheme = new Schema({_id : String, user : String,label : String, secretkey : String,subsperday : Number,subsperdayremain : Number, sensor : [{ id : String, label : String}]})

var userskema = new Schema({_id : String,username : String,email : String, password : String,first_name : String,last_name : String,is_admin : Number})

var Nodes = mongoose.model('nodes', userscheme)
var Skema = mongoose.model('user', userskema)

When i run my program, i have error user variable on Skema.findOne({_id: node.user}, function(err, user) return null. When i print node.user it's print id like what i want.

Can anyone help me ?



via andri warda

No comments:

Post a Comment