Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2479

Add Before/After for primitive.ObjectId to include counter

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: API
    • None

      When working with mongodb documents where you do an insert of multiple documents at once and let mongodb create the `_id` field they can end up with the same timestamp. This makes it difficult in application code to compare ObjectId fields soley based on the timestamp.

       

      I think we should add `Before(id)` and `After(id)` methods to `primitive.ObjectId` which takes both the timestamp and counter field into consideration when comparing ObjectId so that it matches the sort order comparisons done on the server.

       

      Common existing code is `firstId.Timestamp().Before(secondID.Timestamp())` but this subtle breaks when doing find queries for many documents created at the same time and trying to iterator it without a capped collection. ie when you do something like `{_id:{$gt:lastIDSeen}}` it ends up not working due to these faulty ID comparisons.

       

      These methods are also required because you cannot do greater than or less than comparisons on a byte array in go. Only the equality operator works.

            Assignee:
            matt.dale@mongodb.com Matt Dale
            Reporter:
            epelc@greatcloak.com Ed Pelc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: