couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "IsoFormattedDateAsDocId" by BenjaminYoung
Date Sun, 21 Apr 2013 00:25:59 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "IsoFormattedDateAsDocId" page has been changed by BenjaminYoung:
http://wiki.apache.org/couchdb/IsoFormattedDateAsDocId?action=diff&rev1=9&rev2=10

Comment:
added Archive.org cached version of the migrating-to-couchdb doc

  = Using an ISO Formated Date as a Doc _id =
- 
  The ISO 8601 http://en.wikipedia.org/wiki/ISO_8601 standard describes a useful scheme for
representing a date string in a Year-Month-DayTHour:Minute:Second.microsecond format. For
time-bound documents in a CouchDB database this can be a very handy way to create a unique
identifier, since javascript can directly use it to create a Date object:
  
  {{{#!javascript
@@ -12, +11 @@

     }
  }
  }}}
- 
  . . . then simply use group_level to zoom in on whatever time you wish to use.
  
  {{{#!javascript
@@ -31, +29 @@

  {"key":[21,thing],"value":10}
  ]}
  }}}
- 
  Another method is using parseint() and datetime.substr() to cut out useful values for a
return key:
  
  {{{#!javascript
@@ -45, +42 @@

      emit([doc.widget, year, month, day, hour, minute], 1);
  }
  }}}
- 
- 
- 
  If you have python views enabled, you can use the datetime module in the same way:
  
  {{{#!python
@@ -56, +50 @@

      dt = datetime.strptime(doc._id, "%Y-%m-%dT%H:%M:%S.%f")
      yield [doc.host, dt.year, dt.month, dt.day, dt.hour, dt.minute], 1
  }}}
- 
  . . .example with reduce function as it appears in the design doc:
  
  {{{#!javascript
@@ -67, +60 @@

     }
  }
  }}}
- A nice example using a date within a document is found here: http://www.couchone.com/migrating-to-couchdb#three
+ A nice example using a date within a document is found here: http://www.couchone.com/migrating-to-couchdb#three
[dead link] [[http://web.archive.org/web/20110130042049/http://www.couchone.com/migrating-to-couchdb#three|Archive.org
copy]]
  

Mime
View raw message