I had around 2000 objects in this collection, a sample object:
I want to extract all object db.collection.find({})
with selected field .select
using Mongoose :
console.time('Execution Time');
const events = await Events.find({}).select(
"-_id -id -expireAt -homeNmae -awayName -competition"
);
console.timeEnd('Execution Time');
The Execution Time is more than 2s everytime, it’s pretty slow in this small collection. May I ask why and how I can improve.
.explain()
:
{
explainVersion: '1',
queryPlanner: {
namespace: 'foodball.events',
indexFilterSet: false,
parsedQuery: {},
queryHash: '17830885',
planCacheKey: '17830885',
maxIndexedOrSolutionsReached: false,
maxIndexedAndSolutionsReached: false,
maxScansToExplodeReached: false,
winningPlan: {
stage: 'PROJECTION_DEFAULT',
transformBy: [Object],
inputStage: [Object]
},
rejectedPlans: []
},
executionStats: {
executionSuccess: true,
nReturned: 1396,
executionTimeMillis: 5,
totalKeysExamined: 0,
totalDocsExamined: 1396,
executionStages: {
stage: 'PROJECTION_DEFAULT',
nReturned: 1396,
executionTimeMillisEstimate: 1,
works: 1397,
advanced: 1396,
needTime: 0,
needYield: 0,
saveState: 1,
restoreState: 1,
isEOF: 1,
transformBy: [Object],
inputStage: [Object]
},
allPlansExecution: []
},
command: {
find: 'events',
filter: {},
projection: {
_id: 0,
id: 0,
expireAt: 0,
homeNmae: 0,
awayName: 0,
competition: 0
},
'$db': 'foodball'
},
serverInfo: {
host: 'ac-omjpzdm-shard-00-02.tmhozcd.mongodb.net',
port: 27017,
version: '6.0.8',
gitVersion: '3d84c0dd4e5d99be0d69003652313e7eaf4cdd74'
},
serverParameters: {
internalQueryFacetBufferSizeBytes: 104857600,
internalQueryFacetMaxOutputDocSizeBytes: 104857600,
internalLookupStageIntermediateDocumentMaxSizeBytes: 16793600,
internalDocumentSourceGroupMaxMemoryBytes: 104857600,
internalQueryMaxBlockingSortMemoryUsageBytes: 33554432,
internalQueryProhibitBlockingMergeOnMongoS: 0,
internalQueryMaxAddToSetBytes: 104857600,
internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600
},
ok: 1,
'$clusterTime': {
clusterTime: new Timestamp({ t: 1689649740, i: 11 }),
signature: {
hash: Binary.createFromBase64("V7X4bMZ0EByYM+mxZcxLQLBjdn0=", 0),
keyId: new Long("7237192774783598597")
}
},
operationTime: new Timestamp({ t: 1689649740, i: 11 })
}
P.S. I didn’t subscribe to any paid plan, will it affect the database performance?