标签: mongodb-ruby

获取MongoDB中列的最高值

我一直在帮助获取mongo文档列的最高值.我可以对它进行排序并获得顶部/底部,但我很确定有更好的方法可以做到这一点.

我尝试了以下(和不同的组合):

transactions.find("id" => x).max({"sellprice" => 0})
Run Code Online (Sandbox Code Playgroud)

但它一直在抛出错误.除了排序和获得顶部/底部之外,有什么好的方法呢?

谢谢!

ruby mongodb mongodb-ruby

28
推荐指数
4
解决办法
3万
查看次数

MongoDB - sort()的数据太多,没有索引错误

我正在使用MongoDB 1.6.3来存储大集合(300k +记录).我添加了一个复合索引.

db['collection_name'].getIndexes()
[
    {
        "name" : "_id_",
        "ns" : "db_name.event_logs",
        "key" : {
            "_id" : 1
        }
    },
    {
        "key" : {
            "updated_at.t" : -1,
            "community_id" : 1
        },
        "ns" : "db_name.event_logs",
        "background" : true,
        "name" : "updated_at.t_-1_community_id_1"
    }
]
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行此代码时:

db['collection_name']
  .find({:community_id => 1})
  .sort(['updated_at.t', -1])
  .skip(@skip)
  .limit(@limit)
Run Code Online (Sandbox Code Playgroud)

我正进入(状态:

Mongo :: OperationFailure(没有索引的sort()数据太多.添加索引或指定更小的限制)

我究竟做错了什么?

database-design mongodb nosql mongodb-ruby mongodb-indexes

21
推荐指数
1
解决办法
1万
查看次数

Ruby组按键值散列

我有一个数组,由MongoDB执行的map/reduce方法输出,它看起来像这样:

[{"minute"=>30.0, "hour"=>15.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>0.0, "count"=>299.0}, 
{"minute"=>30.0, "hour"=>15.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>10.0, "count"=>244.0}, 
{"minute"=>30.0, "hour"=>15.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>1.0, "count"=>204.0}, 
{"minute"=>45.0, "hour"=>15.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>0.0, "count"=>510.0}, 
{"minute"=>45.0, "hour"=>15.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>10.0, "count"=>437.0}, 
{"minute"=>0.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>0.0, "count"=>469.0}, 
{"minute"=>0.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>10.0, "count"=>477.0}, 
{"minute"=>15.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>0.0, "count"=>481.0}, 
{"minute"=>15.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>10.0, "count"=>401.0}, 
{"minute"=>30.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>0.0, "count"=>468.0}, 
{"minute"=>30.0, "hour"=>16.0, "date"=>5.0, "month"=>9.0, "year"=>2011.0, "type"=>10.0, "count"=>448.0}, 
{"minute"=>45.0, "hour"=>16.0, …
Run Code Online (Sandbox Code Playgroud)

ruby hash mongodb mongodb-ruby

17
推荐指数
1
解决办法
1万
查看次数

如何以编程方式获取Mongoid写入的当前数据库?

我使用Mongoid和rails使用Mongoid.override_database("database_name")与多个数据库进行通信.如何以编程方式查找当前数据库?

关于会话的Mongoid文档:http://mongoid.org/en/moped/docs/driver.html 定义覆盖数据库的方法,但没有定义获取当前数据库的方法.

ruby-on-rails mongodb mongoid mongodb-ruby mongoid3

13
推荐指数
2
解决办法
6008
查看次数

如何在没有缓存的情况下检查mongodb查询性能

我的查询需要很长时间才能完成.我喜欢做一些性能测试但是在我检查一次(当前需要约30秒)之后,查询开始运行得更快(<1秒).我认为它必须与mongodb缓存.有没有办法禁用mongodb的缓存或其他方式我可以检查性能?

我在mongohq使用mongodb.使用Ruby on Rails编程3.以下是解释:

{"cursor"=>"BtreeCursor start_-1", "nscanned"=>5276, "nscannedObjects"=>5276, "n"=>25, "millis"=>3264, "nYields"=>0, "nChunkSkips"=>0, "isMultiKey"=>false, "indexOnly"=>false, "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}, "allPlans"=>[{"cursor"=>"BtreeCursor attendees_count_-1", "indexBounds"=>{"attendees_count"=>[[1.7976931348623157e+308, 1]]}}, {"cursor"=>"BtreeCursor images_count_-1", "indexBounds"=>{"images_count"=>[[1.7976931348623157e+308, 2]]}}, {"cursor"=>"BtreeCursor start_-1", "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}}, {"cursor"=>"BtreeCursor start_-1_end_-1", "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]], "end"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}}, {"cursor"=>"BtreeCursor attendees._id_1 multi", "indexBounds"=>{"attendees._id"=>[[BSON::ObjectId('4f0b621e94bb688563000007'),BSON::ObjectId('4f0b621e94bb688563000007')], [BSON::ObjectId('4f0b647d5a8c00acde05236f'), BSON::ObjectId('4f0b647d5a8c00acde05236f')], [BSON::ObjectId('4f0b647d5a8c00acde052370'), BSON::ObjectId('4f0b647d5a8c00acde052370')], [BSON::ObjectId('4f0b647d5a8c00acde052371'), BSON::ObjectId('4f0b647d5a8c00acde052371')], [BSON::ObjectId('4f0b647d5a8c00acde052372'), BSON::ObjectId('4f0b647d5a8c00acde052372')], [BSON::ObjectId('4f0b647d5a8c00acde052373') ... (lots of Object IDs)]]}}}
Run Code Online (Sandbox Code Playgroud)

请注意,我不得不截断一些解释,因为它太长了.存在"大量对象ID"的地方有很多对象ID(~400).

谢谢大家

mongodb mongohq mongodb-ruby

11
推荐指数
2
解决办法
5657
查看次数

得到更新文件的数量mongo

mongo中是否有函数返回更新语句中更新的文档数?

我试图使用,count()但显然更新语句只返回true或false所以我想我得到一个字符串的计数.

谢谢

database mongodb mongoid mongodb-ruby

8
推荐指数
1
解决办法
2587
查看次数

使用mongo-ruby-driver文档更新?

假设如下:

irb> x
irb> => {"_id"=> 123456, "welcome"=>"Hi!", "welcome2" => "Enjoy your stay!"}
irb> coll.class
irb> => Mongo::Collection
Run Code Online (Sandbox Code Playgroud)

如何使用原始mongo-ruby-driver通过使用重写方法和原子更新方法更新与x对应的文档?(见http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Updating_a_Document)

ruby ruby-on-rails mongodb nosql mongodb-ruby

7
推荐指数
1
解决办法
5259
查看次数

4
推荐指数
2
解决办法
2050
查看次数

Ruby on Rails和MongoDB

我有一个新的Ruby on Rails安装,我可以看到默认的开始页面.

我按照本指南将MongoDB安装到Rails.

现在我在运行时遇到此错误rake test:

**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance.
  You can install the extension as follows:
  gem install bson_ext

  If you continue to receive this message after installing, make sure that the
  bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.
Run Code Online (Sandbox Code Playgroud)

我已经安装了bson_ext gem,这意味着现在bson_ext不在我的加载路径中或者gems不是同一个版本.

负载路径在哪里?我该怎么改变它?如何检查宝石是否是同一版本?

ruby rubygems ruby-on-rails mongodb mongodb-ruby

1
推荐指数
1
解决办法
1850
查看次数

Ruby Mongo驱动程序:如何查找日期间隔?

给定初始日期和今天,在该日期之间搜索所有"名称"的查询是什么?

谢谢

mongodb mongodb-ruby ruby-on-rails-3

0
推荐指数
1
解决办法
4470
查看次数