accessing mongodb's object from mapper (MapReduce)

不羁岁月 提交于 2019-12-11 10:29:31

问题


I have an extra question based on the one I asked before: calculate frequency using mongodb aggregate framework

so my data in MongoDB looks like this now:

{
    "data": {
        "interaction": {
            "created_at": "Wed, 09 Apr 2014 14:38:16 +0000"
        }
    },
    "_id": {
        "$oid": "53455b59edcd5e4e3fdd4ebb"
    }
}

before I used to have it like:

[
  {
     created_at: "2014-03-31T22:30:48.000Z",
     id: 450762158586880000,
     _id: "5339ec9808eb125965f2eae1"
  }
]

so to access created_at I was using mapper like:

var mapper = function () {

    if ( this.created_at.getTime() > ( last_date + 10000 ) ) {
...

but as the structure in my database has changed, I tried to change:

this.created_at.getTime()

to:

this.data.interaction.created_at.getTime()

but unfortunately it didn't work out. Thank you for any help


回答1:


Hate to make this that simple but all you want to do when importing these date strings is this:

new Date("Wed, 09 Apr 2014 14:38:16 +0000")

Which will return a proper date type that you actually should be inserting as part of your data.



来源:https://stackoverflow.com/questions/22986336/accessing-mongodbs-object-from-mapper-mapreduce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!