Mongodb aggregate lookup for merged collections?

Issue

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.

Solution

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":"[\"https://image.bitfinicon.com/be/images/2021/10/OTKAR2021-10-0222-40-33_5877034727566088.png\"]","title":"I'm title here"}

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

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

Answered By – Bitfinicon

Answer Checked By – Senaida (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.