When the mongodb table is associated and queried, why does it always prompt that the user does not exist?

Two tables in

mongodb, one is users and the other is called userDetails. What needs to be done now is that according to the user details corresponding to the userId query, the query is operated in userDetails.
has been tested that the data in the table does exist, can log in successfully, and can return token. That is, when querying according to id, the mongodb terminal can display the user that has been queried and return an object, but it can"t be tested in postman.

 const mongoose = require("mongoose");
 const Schema = mongoose.Schema;
 const UserDetailsSchema = new Schema({
    userId:{
        type: Schema.Types.objectId,
        ref:"users"
    },
    company:{
        type:String
    },
    website:{
        type:String
    }
 })
const UserDetailsSchema = require("../../models/UserDetails");
const passportUser = passport.authenticate("jwt",{ session: false });

router.get("/getUser",passportUser,(req,res) => {
    const errors = {};
    UserDetailsSchema .findOne({user:req.user.id}).then((user) => {
        if(!user){
            errors.noProfile = "";
            return res.status(404).json(errors);
        }
        //
        res.json(user);
    }).catch(err => {
        res.json(err)
    });
});

Test in pastman always hints:

clipboard.png

Header token:

clipboard.png

:

clipboard.png

I am a novice, and I can"t find similar problems on the Internet. The data clearly exist, so why do I keep reminding users that they don"t exist? Did I write something wrong? Ask for advice, thank you!

Mar.26,2022

req.user.id print it out?


is based on userId instead of user query:

UserDetailsSchema.findOne({userId: req.user.id})...
Menu