Add Before/After for primitive.ObjectId to include counter

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Done
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
            Reporter:
            Ed Pelc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: