Mongodb aggregate lookup for merged collections?


Merged queries takes more requests in frontend, for instance having a username query from user collection and having a query from productpost, costs server process power.

My Q is can we have aggregate function, checked previous ones however, they are for mongoose or older versions.


After much time spent on this. The easiest way to do this is via requests than lookups since it will require to go through all documents to find:

Here is mongodb document structure

{"_id":{"$oid":"6198b5cf985bb6b616480463"},"userid":{"$oid":"613dfcca9e7e2014c12dfeef"},"attach":"[\"\"]","title":"I'm title here"}

Then in the JS you call requests (Using Sveltekit new generation):

<div class="author-name">
            {#if === 'aldolap'}
                <div class="author-name-prefix">{product.price} TL</div>
                {#await getuserhere2(product.userid)}
                {:then number}
                <a href={`/u/` + number.username + `_` + `${product.userid}`} >{number.username}</a>
                {:catch error}
                    <p style="color: red">{error.message}</p>

Answered By – Bitfinicon

Answer Checked By – Senaida (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.