Objective I'm trying to pull the qr documents attached to each user (which have a maximum of six) and return both the documents and subdocuments from the my mongoDB using below controller function.
Function
const Qr = require('../models/qr');
const mongoose = require('mongoose');
module.exports.showActivations = async (req, res) => {
const qrCodes = await Qr.find({ user: req.params.id });
console.log(qrCodes);
};
Expected results An example below shows how I expected the results to be returned by showing the subdocument details within 'redirect'
{
_id: new ObjectId("6317ad944f0f1db567b9608c"),
redirect: [
name: "Test",
url: "https://testurl.com"
qrcode: "data:image/png;base64,iVBORwasdf..."
],
user: new ObjectId("6310a2da50448e982336784a"),
__v: 0
}
Actual behavior
I am receiving [ [Object] ] instead of the redirect subdocuments with each document.
{
_id: new ObjectId("6317ad944f0f1db567b9608c"),
redirect: [ [Object] ],
user: new ObjectId("6310a2da50448e982336784a"),
__v: 0
}
qr.js (model)
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const qrSchema = new Schema({
redirect: [{
name: String,
url: String,
qrcode: String,
}],
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
event: {
type: Schema.Types.ObjectId,
ref: 'Event'
},
});
module.exports = mongoose.model('Qr', qrSchema);
How do I yield the full qr document and subdocument details from my query?