[SERVER-857] add get_timestamp method to ObjectId representation in the server's embedded interpreter Created: 31/Mar/10 Updated: 12/Jul/16 Resolved: 15/Jun/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | 1.5.3 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Andrew Burrows | Assignee: | Aaron Staple |
| Resolution: | Done | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
See emails below for an example: I don't think the ObjectId representation in the server's embedded
On Wed, Mar 31, 2010 at 3:19 PM, Andrew Burrows <burrowsa@gmail.com> wrote: ; }', ), >> >> > finalize = 'function(out){ out.yavg = >> >> > out.ysum / out.count }') >> >> > >> >> > Ideally I'd replace it with something like: >> >> > >> >> > # here is an insert - look no ts >> >> > db.box.insert(dict(x=randint(0, 500), y=randint(0, 100))) >> >> > >> >> > # here is a query >> >> > db.box.group(key = 'function(obj){ return { ts : 300 * >> >> > parseInt(obj._id.timestamp/300) }; }', >> >> > condition = {'_id.timestamp' : {'$gt': >> >> > ts(datetime.now() - timedelta(hours=24)) }}, >> >> > initial = dict( xmax=0, ysum=0, count=0 ), >> >> > reduce = 'function(obj,prev) { prev.xmax =>> >> > Math.max(prev.xmax, obj.x); prev.ysum += obj.y; prev.count++; } ', ') |
| Comments |
| Comment by auto [ 16/Jun/10 ] |
|
Author: {'login': 'astaple', 'name': 'Aaron', 'email': 'aaron@10gen.com'}Message: |
| Comment by auto [ 15/Jun/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: more tests for |
| Comment by auto [ 15/Jun/10 ] |
|
Author: {'login': '', 'name': 'Van Nguyen', 'email': 'van@metamoki.com'}Message: |
| Comment by Van Nguyen (vnguyen) [ 14/Jun/10 ] |
|
From within a js shell map function, it is easy to get the date: var d = new Date(parseInt(this._id.toString().slice(0,8), 16)*1000), date_str is also easy to customize so you can use it however you need it. If you want this functionality outside of a mapReduce setting, just replace "this._id" with code to access a document's _id field. |
| Comment by Justin Dearing [ 14/Jun/10 ] |
|
I was looking for a way to do this from the mongo shell this morning. It would be really useful. It would be similarly beneficial to be able to get timestamp and mac address for a UUID from the shell, but thats a separate ticket.. |
| Comment by Mathias Stearn [ 14/Apr/10 ] |
|
Aaron, could you add this to the JS API? |
| Comment by auto [ 14/Apr/10 ] |
|
Author: {'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}Message: ObjectID from Date_t |
| Comment by auto [ 14/Apr/10 ] |
|
Author: {'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}Message: Convert OID to datetimes |