Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-350

Append a date as std::time_t to BSONObj from a stream

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 1.1.2
    • Affects Version/s: None
    • Component/s: Internal Client, Usability
    • None

      A small enhancement just to be able to do:

      BSONObj o = BSON("date" << std::time(0));

      Currently, we have to manipulate BSONObjBuilder::appendDate() in order to append a date from a std::time_t.
      There is no append() overload which takes an unsigned long long (in the case we would like to cast std::time_t)

      diff --git a/db/jsobj.h b/db/jsobj.h
      index 3afc916..8783f5e 100644
      — a/db/jsobj.h
      +++ b/db/jsobj.h
      @@ -1167,6 +1167,13 @@ namespace mongo

      { b.append(n); return *this; }

      +
      + /** Append a date from a std::time_t */
      + void append(const char *fieldName, std::time_t dt)

      { + b.append((char) Date); + b.append(fieldName); + b.append(dt*1000); + }

      /** Append a BSON Object ID (OID type). */
      void appendOID(const char *fieldName, OID *oid = 0 , bool generateIfBlank = false ) {

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            metagoto metagoto
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: