在mongodb导入中更新和插入

在mongodb导入中更新和插入,mongodb,Mongodb,以下命令正确地从csv文件导入数据。但问题是同一个数字有两个条目。 我需要同一文档中417176718的两个条目(因此没有$set)。如何使用mongo导入保持这两个值 cat final.txt number, date, duration, type, destination 417176718 , 2013-01-23 20:09:00 , 1 , NORMAL_CLEARING , 61998487 409334392 , 2013-01-24 11:25:18 , 40 , NO_AN

以下命令正确地从csv文件导入数据。但问题是同一个数字有两个条目。 我需要同一文档中417176718的两个条目(因此没有$set)。如何使用mongo导入保持这两个值

cat final.txt
number, date, duration, type, destination
417176718 , 2013-01-23 20:09:00 , 1 , NORMAL_CLEARING , 61998487
409334392 , 2013-01-24 11:25:18 , 40 , NO_ANSWER , 09821973636
919480909 , 2013-01-25 20:58:00 , 40 , NORMAL_CLEARING , 09919480909
417176718 , 2013-01-24 20:09:00 , 1 , FAILED , 61998487

mongoimport -d mydb -c vcalls --type csv --file final.txt --headerline

这正是map reduce的用途

在数据库中获得该属性后,运行一个map reduce,如下所示:

mapper= function(){emit(this.number, {'data':[{'date':this.date, 'duration':this.duration, 'type':this.type, 'destination':this.destination}]});}

reducer = function(k,v){
    data=[];
    for (i=0;i<v.length;i++){
          for (j=0;j<v[i].data.length;j++){
                data.push(v[i].data[j]);
         }
    }
    return {'data':data}
}
db.vcalls.mapReduce(mapper, reducer, 'reducedcalls')
mapper=function(){emit(this.number,{'data':[{'date':this.date,'duration':this.duration,'type':this.type,'destination':this.destination}];}
减速器=功能(k,v){
数据=[];

对于(i=0;我认为您必须编写自己的脚本才能执行此操作。MongoImport不会为您执行此操作。太好了。由于某些版本问题,我不得不使用out:{inline:1}。如果我有数百万条这样的记录,它会工作吗?如果您想要数百万条,您将希望它们包含在新集合中。请尝试{out:'newcollection'}我遇到一个异常:从JavaScript转换到BSON失败:对象大小17037962超过16793600字节的限制#我如何通过这个异常,因为我不需要这么大的文档,但需要所有其他文档。Amazon m3.xlarge实例在大约45分钟内处理了大约2200万条记录。很有趣!