登录
首页 >  Golang >  Go问答

合并集合的Mongodb聚合查找方法?

来源:stackoverflow

时间:2024-02-13 16:39:24 342浏览 收藏

在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《合并集合的Mongodb聚合查找方法?》,聊聊,希望可以帮助到正在努力赚钱的你。

问题内容

合并查询需要更多时间来处理请求,例如从用户集合中进行用户名查询并从productpost中进行查询,从用户端发送更多请求会消耗服务器处理能力。

我的问题是我们可以为最新的 golang mongodb 集成提供聚合函数吗?


正确答案


花了很多时间在这上面。最简单的方法是通过请求而不是查找,因为它需要遍历所有文档才能查找:

这是mongodb文档结构

{"_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"}

然后在js中调用requests(使用新一代的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>...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>

以上就是《合并集合的Mongodb聚合查找方法?》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>