英文:
Mongodb aggregate lookup for merged collections?
问题
合并查询会花费更多的时间,例如从用户集合中获取用户名查询和从产品帖子中获取查询,会导致服务器处理更多的请求,从用户端发送更多的请求。
我的问题是,最新的golang mongodb集成是否可以使用聚合函数?
英文:
Merged queries takes more time for requests, for instance having a username query from user collection and having a query from productpost, costs server process power with more requests sent from userend.
My Q is can we have aggregate function for the latest golang mongodb integration?
答案1
得分: 0
经过很长时间的努力,最简单的方法是通过请求而不是查找来完成,因为这将需要遍历所有文档来查找:
以下是mongodb文档结构:
{"_id":{"$oid":"6198b5cf985bb6b616480463"},"userid":{"$oid":"613dfcca9e7e2014c12dfeef"},"attach":"[\"https://image.bitfinicon.com/be/images/2021/10/OTKAR2021-10-0222-40-33_5877034727566088.png\"]","title":"我是标题"}
然后在JS中调用请求(使用Sveltekit新一代):
<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>...等待中</p>
{:then number}
<a href={`/u/` + number.username + `_` + `${product.userid}`} >{number.username}</a>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</div>
英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论