What is the length maximum for a string data type in MongoDB used with Ruby?

This other question should answer your question: Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure consistent performance. Note that in the picked answer for that question … Read more

How can I see raw mongoDB queries with Mongoid

I think I got an answer. This is follow dsims answer and also from what I’ve seen in the documentation regarding logging. I have an initialize file (config/initializers/mongoid.rb) and in there I have: Mongoid.logger = Logger.new($stdout) Mongo::Logger.logger = Logger.new($stdout) It dumps out the mongo info the console. You probably want to change this for a … Read more

Finding mongoDB records in batches (using mongoid ruby adapter)

With Mongoid, you don’t need to manually batch the query. In Mongoid, Model.all returns a Mongoid::Criteria instance. Upon calling #each on this Criteria, a Mongo driver cursor is instantiated and used to iterate over the records. This underlying Mongo driver cursor already batches all records. By default the batch_size is 100. For more information on … Read more

How can I disable MongoDB log messages in console?

This logging is coming from the Ruby Mongo driver. The default logging level seems to be Logger::DEBUG. Change it to something higher to disable the debug output: Mongo::Logger.logger.level = Logger::FATAL To make the driver log to a logfile instead: Mongo::Logger.logger = Logger.new(‘mongo.log’) Mongo::Logger.logger.level = Logger::INFO Note that if you’re using the Mongoid ODM, then you … Read more

MongoDB: count the number of items in an array

In MongoDB 2.6, the Aggregation Framework has a new array $size operator you can use: > db.mycollection.insert({‘foo’:[1,2,3,4]}) > db.mycollection.insert({‘foo’:[5,6,7]}) > db.mycollection.aggregate([{$project: { count: { $size:”$foo” }}}]) { “_id” : ObjectId(“5314b5c360477752b449eedf”), “count” : 4 } { “_id” : ObjectId(“5314b5c860477752b449eee0”), “count” : 3 }