[CSHARP-281] PopFirst and PopLast do the opposite jobs Created: 25/Jul/11  Updated: 02/Apr/15  Resolved: 26/Jul/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.1
Fix Version/s: 1.2

Type: Bug Priority: Major - P3
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Major Change

 Description   

Here is the PowerShell script that shows the bug:
(on the other hand, it is not even needed, just double check the driver code of these methods)

Add-Type -Path MongoDB.Driver.dll

  1. DOCS: http://www.mongodb.org/display/DOCS/Updating
  1. Output:
    Unknown macro: { "$pop" }
  2. Expected, see DOCS:
    Unknown macro: { $pop }

    $PopFirst = [MongoDB.Driver.Builders.Update]::PopFirst("name")
    $PopFirst.ToString()

  1. Output:
    Unknown macro: { "$pop" }
  2. Expected, see DOCS:
    Unknown macro: { $pop }

    $PopLast = [MongoDB.Driver.Builders.Update]::PopLast("name")
    $PopLast.ToString()

Note: I have also tried some real example but the code is not so easy to share. Yes, these function do the opposite job, as if their bodies are swapped by mistake.



 Comments   
Comment by Robert Stam [ 26/Jul/11 ]

The implementations PopFirst and PopLast were reversed. If you compensated for this by using the opposite method then this fix will break your code.

Comment by Robert Stam [ 26/Jul/11 ]

If you ever need to write code that does different things depending on which version of the driver it is using, you can discover the version of the driver at runtime using:

var assembly = typeof(MongoServer).Assembly;
var version = assembly.GetName().Version;

In this particular case, if you want your code to work before and after this fix you could avoid using Update.PopFirst and Update.PopLast and just build the update modifier directly:

var update = new UpdateDocument("$pop", new BsonDocument("x", -1)); // instead of PopFirst

Comment by Roman Kuzmin [ 25/Jul/11 ]

Yes, the fix will break the workaround. It will be more difficult to watch both official 1.1 and the latest version built from sources.
Such is life

Comment by Robert Stam [ 25/Jul/11 ]

This is going to be a backward breaking fix. If you compensated for this bug by calling the opposite function you will be affected when they start doing what they are supposed to be doing.

Comment by Robert Stam [ 25/Jul/11 ]

That's definitely a mistake. Thanks for reporting this.

Generated at Wed Feb 07 21:36:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.