Is there a way to set and later access a reference object without calling populate ?
I have a large object, let's call it 'user' of type User which is kept in memory.
Now I have a schema which has a reference to a User object. It looks like this :
var Room = new mongoose.Schema({
...
owner : { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
});
when creating a new room referencing that user I can write :
var room = new Room({ owner: user });
or
var room = new Room({ owner: user._id });
and save it in database :
room.save(function(err) { ... });
This works.
Now I want to keep 'room' in memory and access the 'user' object from it.
I don't want to reload the whole user object from database by calling populate('owner').
I just want to write something like :
room.set('owner', user);
and not have the owner property be set to user._id
How can I do that ?
but if I call room.save() after that the owner reference will be replaced by the whole user document.
Thanks.