ts-mongoose icon indicating copy to clipboard operation
ts-mongoose copied to clipboard

Getting the ObjectId from an non-populated refs

Open Onimishra opened this issue 5 years ago • 0 comments

Based on example4, the non-populated ref has type Types.ObjectId | Comment. It is possible to get it to become Comment, by calling populate and that makes sense - at that point we are sure that the object has been populated and contains Comment.

However, up until that point, shouldn't the type be Types.ObjectId? Or at least provide a depopulateTs method that would reduce the type to Types.ObjectId and call depopulate underneath (just like populateTs does).

It might be that I'm doing something wrong, so please if you know of a better way to pass only the ObjectId of a ref after I just loaded up the containing document, let me know :)

Onimishra avatar Dec 04 '19 10:12 Onimishra