How mongo identifies the first row when using updateOne,deleteOne

Dear,
how mongo identifies the first row when using updateOne,deleteOne.
can you explan the mechnism.
thanks a lot.

Hi @Yi_deng ,

The first document that is scanned by the filter side of the operation.

So if you match and sort on a criteria the first document that will be fetched will be applied with the update part…

Thanks
Pavel

1 Like

hi pavel
thanks a lot.
if i do not include sort operation in update, then ,how mongo identifies the first row?

By the natural order of the documents.

Usually it will be the insert order. But when not doing sort it can potentially be any of the documents answering the criteria…

thanks for your kindly help

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.