When I log a user that I made with schema in mongoose, I get something named <Revoked Proxy>, so that I can not loop over this links array, or do anything to it
model {
'$__': InternalCache {
activePaths: StateMachine { paths: [Object], states: [Object] },
skipId: true
},
'$isNew': false,
_doc: {
_id: ObjectId { [Symbol(id)]: [Buffer [Uint8Array]] },
username: 'turmuka',
password: 'asdf',
email: '[email protected]',
categoryLinks: [ [EmbeddedDocument], [EmbeddedDocument] ],
links: <Revoked Proxy>,
imagelink: '/images/blank',
plan: '0',
bakiye: 0,
phoneNumber: 766951259,
__v: 14
}
}
The schema is as follows, only the links matter here,
const userSchema = new Schema({
username: {
type: String,
unique: true
},
password: String,
email: {
type: String,
unique: true
},
categoryLinks: {
type: [categoryLinkSchema],
validate: [function(doc) {
for(let d of doc){
const duplicates = this.categoryLinks.filter(function(c){
return c.link === d.link || c.label === d.label;
})
if(duplicates.length > 1){
return false;
}
}
}, 'Each categoryLinks.label must be unique.']
},
links : { type : Array , "default" : [] },
imagelink: String,
plan: String,
bakiye: Number,
phoneNumber: Number
});
When I try to push something to the links array for the user, I try this but this seem not to be the correct,
userModel.findOne({
username: req.session.username
}).then(
(user) => {
console.dir(user)
res.render('takip-ettigim-indirimler', {links: user.links});
}
).catch(
(error) => {
console.log('Error at login phase: ' + error.code + " error: " + error);
}
);
This seem to not work, so should I use [EmbeddedDocument] like I did with categoryLinks or is there a way to do it with just links : { type : Array , "default" : [] }, declaration?