I'm working with mongoose populations and I don't understand if I'm doing anything wrong or it does not work the way I think it should work..
I have 2 schemas: User:
{
things: [{ type: Schem.Types.ObjectId, ref: 'Thing' }]
}
and Thing:
{
_creator: { type: Schema.Types.ObjectId, ref: 'User' }
}
Now if I save Thing and provide existing user ID as _creator value:
let thing = new Thing({ _creator: user.id })
thing.save();
then fetch that thing and use Thing.find().populate('_creator')...
I get correct results with creator field populated and replaced with user object.
BUT if I fetch users object, I don't see that things array would be modified in any way and it's still empty.
What I expect - things array to contain newly created thing ID What I get - empty things array
Question - does it work correctly/as expected and I need to manually save ref on user object or am I doing something wrong?