Hi.
I was used documentDB 4.0.0 version.
It is my code. (This function make Numeric ID sequence)
private async generatePushMessageSequence(): Promise<number> {
const result = await this.sequenceModel
.findOneAndUpdate(
{ _id: 'XXX' },
{ $inc: { sequence: 1 } },
{ new: true, upsert: true },
)
.exec();
return result.sequence;
}
But sometimes this operation is too slow
{"op":"command","ts":1644926941441,"ns":"test.xxx",
"command":{
"findAndModify":"xxx",
"query":{"_id":"XXX"},
"remove":false,
"new":true,
"upsert":true,
"fields":{},
"update":{"$inc":{"sequence":1}},"lsid":{"id":{"$binary":"XXX","$type":"4"}},"$db":"test"},
"nMatched":1,
"nModified":1,
"protocol":"op_query",
"millis":1472,
"planSummary":"IXSCAN",
"execStats":{
"stage":"UPDATE",
"nReturned":1,
"executionTimeMillisEstimate":0,
"inputStage":{
"stage":"LIMIT_SKIP",
"nReturned":"1",
"executionTimeMillisEstimate":"1441.544",
"inputStage":{
"stage":"IXSCAN",
"nReturned":"1",
"executionTimeMillisEstimate":"2.736",
"indexName":"_id_",
"direction":"forward"
}
}
},
}
In "LIMIT_SKIP" stage, 1441ms needed.
I suspecting mognoose 'findOneAndUpdate' function called documentDB 'findAndModify' && limit(1)' query.
But I cannot understand, 'Why too slow in LIMIT_SKIP stage.'. Bcz, nReturn is already only 1 doc.
Can I get some guide for this slow situation?