Situation:
I have 1 million users and I want to search for them by tags.
Here's the diagram:
const Account = new Schema({ tags: { type: [String], default: ['cats'] } })
Here is the first request:
const query = { tags: 'cats'} const fields = { _id: 0 } const options = { skip: 0, limit: 5 } Account.find(query, fields, options)
After calling find the Mongoose method will start the search and return the first 5 records that it matches. Performance in this case is optimal.
Here's the second request:
const query = { tags: 'cats'} const fields = { _id: 0 } const options = { skip: 500 000, limit: 5 } Account.find(query, fields, options)
What happens in this case is of interest to me.
Does Mongoose 500,000 records and then return the next 5 records?
Or does it somehow βjumpβ onto 500,000 elements without the need to compare them in advance?
I am trying to understand how effective this process is, and whether I can somehow improve it. Do you have any tips?
source share