These are chat archives for Automattic/mongoose

27th
Mar 2018
Kev
@lineus
Mar 27 2018 10:42
@adamgarcia4 gist here
Adam Garcia
@adamgarcia4
Mar 27 2018 10:48

@lineus Ahh, this is such a simple approach! And one more question, if I have a 3-level deep comment tree structure (a comment on a comment on a comment), is there a recursive populate method that will populate all the comments together in one round-trip from the server?

I know that I can just create another populate method on the document that is returned to me, but I'm thinking that there has to be a way that a multi-deep comment tree can be achieved in one Mongo HTTP call

Kev
@lineus
Mar 27 2018 10:51
@adamgarcia4 there's an example in the docs for populating multiple levels here
it takes a bit of trial and error for me to get the paths right, but it can be done in one go for sure.
Adam Garcia
@adamgarcia4
Mar 27 2018 10:59
as far as I see this, I have to know ahead of time how many levels down I want to populate. But in the case where I don't know how many levels deep the comments are, is this going to be a problem?
Kev
@lineus
Mar 27 2018 11:01
that's an interesting point. I'll have to give that some thought and play around with it.
I'll be back around in a couple hours :)
Adam Garcia
@adamgarcia4
Mar 27 2018 11:21
Okay! Actually, I found https://docs.mongodb.com/ecosystem/use-cases/storing-comments/ where they address comments use cases specifically. It has a solution for my use case (comments) by storing a full path to the comment which contains within it the slug_id of its parents. However, for the general case of an n-level deep populate it doesn't address.
I didn't know that mongodb supports finding based on regex. This opens up a whole world of new possibilities!