'Are Mongoose arbitrary queries as slow compared to DynamoDB Scan?

I am reading in this blog: DynamoDB is bad for analytics. It is true that because you cannot run arbitrary queries against DynamoDB tables (technically speaking you can but it's extremely inefficient due to Scan nature), you cannot perform ad-hoc reports of your data

So I am wondering that if Mongo does sort/order those things in a better way so that running something like this doesnt need to scan the entire collection

Person.
  find({
    occupation: "student",
    age: { $gt: 17, $lt: 66 }
  }).
  sort({ occupation: -1 }).
  select({ name: 1, occupation: 1 }).
  exec(callback);


Solution 1:[1]

for performance. you need to try proper indexing in the database. it's making a big effect on data queries. for further information, you can review this main source site. Query-Plan-in-mongo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RONAK SUTARIYA