I created a function to create a profile document, based on a schema, into mongoDB, which works so far:
const createUpdateProfile = (req, res) => {
let uuid = req.user.identities[0].id;
let provider = req.user.identities[0].provider;
let email = req.user.email;
let firstName = req.user.name.split(' ').slice(0, -1).join(' ');
let lastName = req.user.name.split(' ').slice(-1).join(' ');
let pictureUrl = req.user.picture;
let profileToSafe = new Profile({
uuid: uuid,
provider: provider,
email: email,
firstName: firstName,
lastName: lastName
});
const profile = Profile.findOne({ uuid });
if (profile !== null) {
profileToSafe.save();
}
res.status(200).send('successful operation');
}
I checked the DB and the document has been stored there.
But I cannot read it.
const getProfile = (req, res) => {
let uuid = req.user.identities[0].id;
Profile.findOne({ uuid: uuid }), function (obj) { console.log(obj) }, function (err) { console.log(err) };
res.status(200).send('successful operation');
}
There is simply no console log output. Not even a null or an error.
I did as mentioned here also I tried to console log findOne function but it returns kind of the whole database, including the authentication data.