You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two methods
Doctrine\MongoDB\Query\Expr::popFirst()
Doctrine\MongoDB\Query\Expr::popLast()
use wrong $pop value.
Current behavior
according to mongodb manual
The $pop operator removes the first or last element of an array. Pass $pop a value of -1 to remove the first element of an array and 1 to remove the last element in an array.
pop first is -1, pop last is 1,
in the code is just reversed.
The text was updated successfully, but these errors were encountered:
Moved to the 2.0 line since that's the only bug fix to do in ODM. For 1.x, the error is in doctrine/mongodb and will be fixed in a separate release today. Thanks for the report!
doctrine/mongodb 1.6.3 was just released containing the fix for this issue. For 2.0 (the current master branch, #1831 will port the fix to ODM.
Since I was bored this morning, I decided to dig into the history of this bug:
It was introduced 8 years ago (May 2010) when a young developer added update methods to the ODM query object and made a tiny mistake in the documentation (First is 1 and last is -1): 795dc99#diff-d9cea82dc18423811aa7d0cc84fdbe25R673
A few hours later, the same developer would then refactor the pop method into popFirst and popLast, incorporating their own documentation mistake and creating the wrong behavior you found: 0632861#diff-d9cea82dc18423811aa7d0cc84fdbe25R714.
This was released as ODM 1.0.0-BETA4 in August 2010, which would be the first version to contain the bug.
From then, the issue made its way to the new doctrine/mongodb library in December of 2010 later to be released as 1.0.0-BETA1: doctrine/mongodb@98e70d3#diff-0a4ad011a43c676e967fac2188a7ee0fR291
The bug had its big homecoming 7 years later in December 2017 when we dropped doctrine/mongodb in favour of the MongoDB PHP library: #1553 (I would link the exact line, but GitHub really doesn't like large commits and pull requests).
So, again, thank you for finding and reporting an 8 year old bug that caused wrong data to be removed - you were either the first person to hit it or the first to care enough about their data to report it as a bug. I hope you enjoyed that little trip down the long and colourful history of this bug.
Bug Report
Summary
Two methods
Doctrine\MongoDB\Query\Expr::popFirst()
Doctrine\MongoDB\Query\Expr::popLast()
use wrong $pop value.
Current behavior
according to mongodb manual
The $pop operator removes the first or last element of an array. Pass $pop a value of -1 to remove the first element of an array and 1 to remove the last element in an array.
pop first is -1, pop last is 1,
in the code is just reversed.
The text was updated successfully, but these errors were encountered: