Questions tagged [mongodb-ruby]

Officially supported Ruby driver for MongoDB.

The MongoDB Ruby driver is the officially supported Ruby driver for MongoDB. It’s written in pure Ruby and is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoid.

Links

Related tags

50 questions
28
votes
9 answers

Getting the highest value of a column in MongoDB

I've been for some help on getting the highest value on a column for a mongo document. I can sort it and get the top/bottom, but I'm pretty sure there is a better way to do it. I tried the following (and different combinations):…
roloenusa
  • 761
  • 1
  • 10
  • 19
21
votes
4 answers

MongoDB - too much data for sort() with no index error

I am using MongoDB 1.6.3, to store a big collection (300k+ records). I added a composite index. db['collection_name'].getIndexes() [ { "name" : "_id_", "ns" : "db_name.event_logs", "key" : { "_id" : 1 …
Vlad Zloteanu
  • 8,464
  • 3
  • 41
  • 58
19
votes
4 answers

Ruby group hashes by value of key

I have an array, which is output by a map/reduce method performed by MongoDB, it looks something like this: [{"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,…
JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
16
votes
3 answers

How can I check mongodb query performance without cache

I have a query that takes too long to finish. I like to do some performance tests but after I check for one time (that takes currently ~30 seconds) the query start to run a lot faster (< 1 second). I assume it has to be with the mongodb caching. Is…
Gluz
  • 3,154
  • 5
  • 24
  • 35
14
votes
5 answers

How to programmatically get the current database Mongoid is writing to?

I am talking to multiple databases using Mongoid.override_database("database_name") using Mongoid with rails. How do I find the current database programmatically? Mongoid docs on sessions: http://mongoid.org/en/moped/docs/driver.html define methods…
8
votes
2 answers

get number of updated documents mongo

Is there a function in mongo to return the number of documents that were updated in an update statement? I have tried to use count() but apparently the update statement only returns true or false so i think I'm getting the count of a string. Thanks
K2xL
  • 9,730
  • 18
  • 64
  • 101
7
votes
1 answer

Document updates using mongo-ruby-driver?

Assuming the following: irb> x irb> => {"_id"=> 123456, "welcome"=>"Hi!", "welcome2" => "Enjoy your stay!"} irb> coll.class irb> => Mongo::Collection How can I use the raw mongo-ruby-driver to update the document corresponding to x by using both…
Philip Wernersbach
  • 461
  • 1
  • 5
  • 11
4
votes
2 answers

What's the best state machine gem to mongoid?

What's the best state machine gem to use with mongoid?
4
votes
0 answers

Sporadic NoServerAvailable errors from mongoid

On production we get a steady stream of seemingly random Mongo::Error::NoServerAvailable errors. Maybe 3 a day. The replica set in question has not experienced any elections, and there is nothing unusual about its performance during these…
cailinanne
  • 8,332
  • 5
  • 41
  • 49
3
votes
2 answers

Nested Group By Function with MongoDB

I'm pretty new with MongoDB, long time MySQL guy and am running into a little roadblock. Given the below sample data: TeamID Day OrderAmount 100      4/1   50 100      4/1   40 200      4/2   50 100      4/2   20 I'm trying…
james
  • 491
  • 6
  • 15
3
votes
1 answer

Experiencing delay when fetching 100th row

I am fetching all the rows from the collection and experience delay on 100th row. I understand that find method returns cursor and not all the data up front and at certain point need to fetch more data. But the 100th row is the only delay. Checking…
Ilya Tsuryev
  • 2,766
  • 6
  • 25
  • 29
2
votes
2 answers

Is it possible to lower the max document size in Mongo or otherwise restrict document size on update?

I want to enforce a maximum document size that is lower than the system actually supports. Doing so on an insert is reasonable -- I can just check before insertion. Doing so on an update is less clear. I don't want to have to read back the entire…
ilya
  • 71
  • 2
2
votes
1 answer

Mongoid order_by boolean

I have a notifications table in my database which contains the attributes: timestamp:datetime and read:boolean. What I want is to query and order my notifications; first by if they are read or not, then after which timestamp they've got, then limit…
zeeraw
  • 5,197
  • 1
  • 21
  • 27
2
votes
1 answer

Rails 3: Create a valid JSON Object from an Array of data

I am taking information from my MongoDB database (@bs). @bs has tons of information that I'm not interested, so what I need is to cycle trough all the information and create a new object with the information I need. For that, I created a new array…
Donald
  • 243
  • 4
  • 10
2
votes
0 answers

Queries on embedded documents with Mongoid/MongoDB (Rails)

I'm trying to figure out what the performance is with Mongoid when doing queries on embedded documents. I'm quite new to Mongoid and MongoDB, so if you spot anything that you think is bad practice, please let me know. A use case: Suppose I have a…
1
2 3 4