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 DougShawhan. http://wiki.apache.org/couchdb/IsoFormattedDateAsDocId?action=diff&rev1=1&rev2=2 -------------------------------------------------- } }}} - Another useful Javascript pattern is to use datetime.substr to create useful values for a return key: + Another advantage is using parseint() and datetime.substr() to cut out useful values for a return key: {{{#!javascript function (doc) { @@ -46, +46 @@ ]} }}} + If you have python views enabled, you can use the datetime module in the same way: + + {{{#!python + def fun( doc ): + from datetime import datetime + 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 + { + "doo_dad_finder": { + "map": "def fun(doc):\n from datetime import datetime\n if doc['errors']:\n dt = datetime.strptime(doc._id, '%Y-%m-%dT%H:%M:%S.%f')\n for doo_dad in doc['doo_dads']:\n yield [doo_dad, dt.year, dt.month, dt.hour], 1", + "reduce": "def fun(keys, values, rereduce):\n return sum(values)" + } + } + }}} A nice example using a date within a document is found here: http://www.couchone.com/migrating-to-couchdb#three
