简体   繁体   English

当查询的结果需要在发送到客户端之前进行操作时,如何从 Mongodb 快速访问大量数据

[英]How do i access a large amount of data fastly from Mongodb when the results from the query need to be manipulated before sending to the client

I have a Mongodb database with React based front-end and Node based back-end with approximately 100000 documents in the collection.我有一个基于 React 的前端和基于 Node 的后端的 Mongodb 数据库,集合中大约有 100000 个文档。 I have already done indexing and I am already using Redis.我已经完成了索引并且我已经在使用 Redis。 I have implemented a search functionality to find all the relevant documents with 'title' property containing the search query and display them to the user.我已经实现了一个搜索功能来查找所有具有包含搜索查询的 'title' 属性的相关文档并将它们显示给用户。 I am also using pagination displaying 20 results per page and there are various filters which a user can apply on the result.我还使用分页显示每页 20 个结果,并且用户可以对结果应用各种过滤器。

Till now what I have done is when a user searches something, a text search on the database is performed.到目前为止,我所做的是当用户搜索某些内容时,会在数据库上执行文本搜索。 All the results of the search are then scored based on their relevance depending on the search query and they are sorted in the order of the scores and returned to the client.然后根据搜索查询的相关性对所有搜索结果进行评分,并按评分顺序对它们进行排序并返回给客户端。 Then when the page is changed or a filter is applied, the changes take place on the javascript front-end side only.然后,当页面更改或应用过滤器时,更改仅发生在 javascript 前端。 Approximately 9000 results means approximately 11 MB of data which takes a hefty amount of time to be sent from the back-end.大约 9000 个结果意味着大约 11 MB 的数据需要很长时间才能从后端发送。

One thing I could do is for every search retrieve all the data from the database and score them and sort them based on scores and return only 20 results to be displayed on the first page but then every time the page is changed or a filter is applied, I will have to do the complete thing again which will take a long time for something as simple as filtering.我可以做的一件事是,每次搜索都从数据库中检索所有数据并对它们进行评分并根据分数对它们进行排序,然后只返回 20 个结果显示在第一页上,但是每次更改页面或应用过滤器时,我将不得不再次做完整的事情,这将需要很长时间才能完成像过滤这样简单的事情。

I would like to know how do I go about it to get the data faster on the client-side while not affecting the speed of filtering and changing pages by a lot.我想知道如何在客户端更快地获取数据,同时又不影响过滤和更改页面的速度。

A suggestion of additional or a different tech stack is also welcome.也欢迎提供额外或不同技术堆栈的建议。 Thank you.谢谢你。

Looks like all this could be easily solved using elasticsearch.看起来所有这些都可以使用 elasticsearch 轻松解决。 Don't do anything on the client side.不要在客户端做任何事情。 All complex queries can be easily handled by elasticsearch in a fraction of milli second. elasticsearch 可以在几分之一毫秒内轻松处理所有复杂的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在发送到客户端之前,如何从 Parse 服务器访问和消毒我的 Javascript 用户 object? - How can I access & sterilize my Javascript user object from Parse server before sending to client? 将变量分配给jQuery getJSON结果中的操作数据 - Assign variable to manipulated data from jQuery getJSON results 如何从客户端点击查询mongodb现有数据? - How to query mongodb for existing data on click from client side? 在发送消息之前如何从数据库中获取信息 - How do I get the information from the database before sending a message 需要呈现MongoDB查询返回结果的特定索引/位置 - Need to render specific index/location of returned results from MongoDB query 如何通过客户端JavaScript从我的node.js服务器访问数据? - How do I access data from my node.js server from client javascript? 在将响应发送回客户之前,您如何等待Mandrill的交付响应? - How do you wait for a delivery response from Mandrill before sending response back to client? 如何从json对象访问和使用多个数据? 我需要做一个数组吗? - How to access and use multiple data from json object? Do I need to make an array? 如何防止客户端在每个GET之前发送OPTION请求? - How to prevent client from sending an OPTION request before every GET? 如何从流访问数据? - How do I access the data from a stream?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM