rnyyvg
Last Updated: February 25, 2016
·
267
· _kellyc_

Replacing the aggregation in search of events

Operations of aggregations (Aggregation) allow users to process all data records through similar operations to SQL "count (*)" command and "group by" and returns the calculated result. It is great when used in ad hoc consultations, they allow amazing things. However, if recurrent and competitors, these queries require much effort that they need to relate data from multiple records. Calls aggregator node are distributed to each shard, and they become responsible for the data that is on your part. The query gathers this data and returns it to the client, causing costs in the allocation of memory and performance.

In the case of Ingresse, all the conditions used in the search for events are handled and stored in an array. Some queries used regexp, which required much of the server. That made a little flexible and nothing performative application.

To obtain increased performance and simplicity in search of events, we chose to eliminate the aggregation and do everything via queries.

For this we use the indices, zeroing the need for additional processes. The query is made within the index itself, allowing competition and recurrence without major problems, resulting in faster queries.

First, create the index indexing keys "title", "description", "tags" and "link" as follows:

db.event.ensureIndex ({'title': 'text', 'description': 'text', 'tags', 'text', 'link': 'text'}, {'DEFAULT_LANGUAGE': 'english' name "busca01"}

The index busca01 canceled the use of regex.

Indexes in MongoDB are very similar to those of relational databases. You can place an index on any attribute.

Second, we conducted a search through the full text search:
db.event.find ({$ text: $ {search: "marcelo"}}, {'title': true, 'description': true, 'tags': true, 'link': true, '_id': false }) .pretty ()

what matters is there
db.event.find ({$ text: $ {search: "marcelo"}})

Changed in version 2.6: MongoDB allows the search feature text by default

The default sort order used is the closest event to the current date as the future. To create this index:
db.event.ensureIndex (eventDate.dateTime {1})

Ready! With these changes had a significant gain in performance, leaving 100 users to 2,000 users per minute / minute in laboratory tests besides consultations have been simpler.

References

http://mongodbwise.wordpress.com/2014/05/22/mongodb-guia-rapido/

SADALAGE, P.; FOWLER, M. NoSQL Essencial - Um Guia Conciso para o Mundo Emergente da Persistência Poliglota. ED. Novatec, 2013