javascript - Mongoose findOne() callback returning null -
i'm trying find user in node app mongoose using
var user = require('../app/models/user'); function mongotest() { var publicaddress = "0x8a6be8979340faa30020b0c1f617d8fd4309679f"; user.findone({"publicaddress": publicaddress}, (err, user) => { if (err) { res.status(500).send(err) } else { console.log(user); } }); }
and err
, user
return null
. other questions here (this , this), seems related mongoose pluralising collections. however, don't think that's issue because users.js has
module.exports = mongoose.model('user', userschema); // have tried module.exports = mongoose.model('user', userschema, 'user');
for completeness, users.js is
var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); // define schema our user model var userschema = mongoose.schema({ local: { username: string, password: string, picturecaption: string, publicaddress: string, contractaddress: string } });
finally, i'm sure public address exists because can see in mongodb robo 3t.
in userschema
publicaddress
part of local
object.
var userschema = mongoose.schema({ local: { username: string, password: string, picturecaption: string, publicaddress: string, contractaddress: string } });
you trying find object publicaddress
it's inside local
object. should edit query follows result.
user.findone({"local.publicaddress": publicaddress}, (err, user) => { if (err) { res.status(500).send(err) } else { console.log(user); } });
Comments
Post a Comment