1

I have a have several mongo databases for separate parts of a website I am making. One of those databases is for sessions. I am using Connect Mongo to store the sessions in the databases. I can't seem to store in to session a ObjectId that references a model I made for a user. But when I read the session I just get the ObjectId I stored and not the object. I already changed stringify to false. Is it possible to do this with Connect Mongo?

I already tried making a schema and store that schema to a session variable to see if it will give back the user object I have referenced to. I included this code below.

var mongoose = require('mongoose');
var DBsessions = require('../../setup/DBconnect.js').DBsessions;

var QuickChatRefScheme = mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    }
});

module.exports = DBsessions.model('QuickChatRef', QuickChatRefScheme);

And to use this I have:

request.session.allowedChatUser = new QuickChatRef({user:new   mongoose.Types.ObjectId(toUser._id)});

Where toUser._id is provided and is a already existing user _id field.

I need the session to ref the user so when node queries the session from the db the user object gets pulled back too.

0 Answers0