Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-245

Enable BSON::ObjectId creation at arbitrary timestamp

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 1.3.0
    • Affects Version/s: 1.2.4
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      Since an ObjectId includes the current timestamp, some people are using that to get document creation time instead of having a separate "created_at" timestamp field.

      With this practice, however, a need arises to be able to create ObjectIds at arbitrary points in time. This is especially needed in testing and importing data from other sources.

      The `ObjectId.from_time` method, while useful for queries, can't be used for generating real IDs because it doesn't ensure that they are unique.

      My idea is: first change the private `generate` method to accept an optional time object (but default to Time.now, to keep present functionality), then change the ObjectId constructor to accept a timestamp and pass it on to `generate`.

      The end usage would be in the form of `BSON::ObjectId.new(time)`.

            Assignee:
            kbanker Kyle Banker
            Reporter:
            mislav Mislav Marohni?
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: