Looking for some assistance with MondoDB.
I have a MongoDB collection with 7.3 million documents, running on a server with 24 cores and 64GB RAM. I have created a text index for a single field.
When I perform text searches using the code below (in MongoShell):
db.getCollection('mycoll').find({$text: {$search: 'my search query'}}).limit(10);
I get results almost instantly. The only problem is that these results are basically useless because they aren't sorted by score (and it's beyond me why this isn't the default behavior, but that's a different topic).
I modify the command to include the sorting by score, as follows:
db.getCollection('mycollection').find({$text: {$search: 'my search query'}, {score: {$meta: 'textScore'}}}).sort({score: {$meta: 'textScore'}}).limit(10);
and the command works, but it now takes about 10 seconds.
For a single or occasional query, it's not a big deal, but when I need to perform 1,000 - 10,000 of such queries in a batch we are talking now several hours of wait time.
I have seen some recommendations about adding "project" and "aggregation" but I don't see any improvement. Maybe I am not doing it right, so I don't want to put additional code here.
Any MongoDB expert that can provide some help would be greatly appreciated!