Tag: mongodb query

mongoid – mongodb,mapreduce获取范围可变或将其传递给输出

在mapreduce中,我有一个范围total_count,用于在分组内容后计算一些东西。 如何在输出中恢复该范围可变? 编辑: map = %Q{ function() { ttotal_commission += this.commission; tuniq_commission += this.commission; // add first if it not goto reduce emit({ip: this.ip, campaign_id: this.campaign_id}, {commission: this.commission, abc: this.commission}); } } reduce = %Q{ function(key, values) { tuniq_commission += values[0].commission; // add 1 and substract laster for uniq var total_commission = 0; values.forEach(function(value) { […]

我可以设置Mongoid查询超时吗? Mongoid不会长时间查询

Mongoid没有超时选项。 http://mongoid.org/en/mongoid/docs/installation.html 我希望Mongoid杀死长时间的查询。 如何设置Mongoid查询超时? 如果我什么都不做,Mongoid会像下面那样等待很长时间。 mongo > db.currentOp() { “opid” : 34973, “active” : true, “secs_running” : 1317, // <- too long! "op" : "query", "ns" : "db_name.collection_name", "query" : { "$msg" : "query not recording (too large)" }, "client" : "123.456.789.123:46529", "desc" : "conn42", "threadId" : "0x7ff5fb95c700", "connectionId" : 42, "locks" : { "^db_name" […]

限制聚合聚合中的聚合

我有这样的集合,但有更多的数据。 { _id: ObjectId(“db759d014f70743495ef1000”), tracked_item_origin: “winword”, tracked_item_type: “Software”, machine_user: “mmm.mmm”, organization_id: ObjectId(“a91864df4f7074b33b020000”), group_id: ObjectId(“20ea74df4f7074b33b520000”), tracked_item_id: ObjectId(“1a050df94f70748419140000”), tracked_item_name: “Word”, duration: 9540, } { _id: ObjectId(“2b769d014f70743495fa1000”), tracked_item_origin: “http://www.facebook.com”, tracked_item_type: “Site”, machine_user: “gabriel.mello”, organization_id: ObjectId(“a91864df4f7074b33b020000”), group_id: ObjectId(“3f6a64df4f7074b33b040000”), tracked_item_id: ObjectId(“6f3466df4f7074b33b080000”), tracked_item_name: “Facebook”, duration: 7920, } 我做一个聚合,ho返回分组数据,如下所示: {“_id”=>{“tracked_item_type”=>”Site”, “tracked_item_name”=>”Twitter”}, “duration”=>288540}, {“_id”=>{“tracked_item_type”=>”Site”, “tracked_item_name”=>”ANoticia”}, “duration”=>237300}, {“_id”=>{“tracked_item_type”=>”Site”, “tracked_item_name”=>”Facebook”}, “duration”=>203460}, {“_id”=>{“tracked_item_type”=>”Software”, “tracked_item_name”=>”Word”}, “duration”=>269760}, {“_id”=>{“tracked_item_type”=>”Software”, […]

mongomapper协会跳过重复

我有一个带有ObjectId数组的Document: Class Task key :user_id, Array many :userlist, class_name: ‘User’, :in => :user_id 在该Array中,我存储了不同的user_id值,有时会重复。 我可以看到重复的user_id使用: @task.user_id.each do |z| puts z end 但是当我使用以下方法获取和关联数据时: @task.userlist.each do |z| puts z.name end 我没有得到重复项:(,只有唯一的ID才能获得关联。为什么?