MongoDB Map & Reduce with Date filter

We are using MongoDB as primary DB at VersionEye, together with MongoID. Software package is a document in the “products” collection. These products collections has a subcollection with “versions”. Assume we want to know how many versions/artifacts existed for a given language to a given time? That is not a simple query in MongoDB. ThisContinue reading “MongoDB Map & Reduce with Date filter”

MongoDB could not restore backup because of “key too large to index” error

Recently I made a db dump on a MongoDB 2.4 server like this: mongodump –db veye_dev And I tried to restore it on a MongoDB 2.6 server like this: mongorestore dump/veye_dev Unfortunately at some point the restore process failed with this error message: mongo error: “Btree::insert: key too large to index, failing There are someContinue reading “MongoDB could not restore backup because of “key too large to index” error”

MongoID Lessons Learned

I am using MongoID to access MongoDB from a Ruby on Rails application. It is a good library. But there are some things I found out during the project, I want to share here. Nothing bad. Just some behaviors should now about. Case Insensitive Search There are different ways to write queries with MongoID. One pretty coolContinue reading “MongoID Lessons Learned”

Failed to connecto to primary node

If you try to connect to MongoDB Replica Set via MognoID and you get this error message here: /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:165:inconnect’: Failed to connect to primary node. (Mongo::ConnectionFailure) from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:500:insetup’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:144:in initialize’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config/replset_database.rb:24:innew’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config/replset_database.rb:24:in configure’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:316:inconfigure_databases’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:119:in from_hash’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:136:inload!’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid.rb:147:in load!’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:33:inclass:Application’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:18:in <module:Versioneye>’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:17:in’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:in require’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:inblock in ‘ fromContinue reading “Failed to connecto to primary node”

Rails + MongoDB ReplicaSet Configuration

This article shows how to configure a Ruby on Rails app for a MongoDB ReplicaSet. How to set up a MongoDB ReplicaSet I described here: MongoDB ReplicaSet Tutorial. And how to configure Rails to work together with MongoDB is described here: Rails + MongoDB Quickstart Tutorial. If you want to connect to a ReplicaSet youContinue reading “Rails + MongoDB ReplicaSet Configuration”

Rails + MongoDB Tutorial. Quickstart.

This is a Quickstart Tutorial for Rails + MongoDB. Ruby on Rails and MongoDB, a document based database, is a pretty good fit. It is very easy to integrate MongoDB with Rails. If you want to know how to install MongoDB, check out this article here: Installing MongoDB on Mac OS X Lion. Or thisContinue reading “Rails + MongoDB Tutorial. Quickstart.”

MongoDB. Growing local.X files

I have a ReplicaSet with MongoDB 2.0.2 on two Debian Linux 6.0 servers. The ReplicaSet is working fine. But on one of the servers I realized that there are a bunch of local.x files. local.0 local.1 … local.22. Each of them 2.1 GB. The actual database/collections are less than 1 GB. I am just wonderingContinue reading “MongoDB. Growing local.X files”

mongodb replicasets with read errors

If you have a ReplicaSet setup with MongoDB and you try to read from a slave node and you get this Exception here: mongdodb, replicates and error: { “$err” : “not master and slaveok=false”, “code” : 13435 } or this here: uncaught exception: count failed: { “errmsg” : “not master”, “ok” : 0 } ThanContinue reading “mongodb replicasets with read errors”

MongoDB Import / Export

If you want to export a whole database on MongoDB, this is the tool you are looking for: mongodump –host <HOST> –port <PORT> –db <DATABASE> –username <USERNAME> –password <PASSWORD> that will export all your collections into a separate folder. Each collection is exported to a single bson file. After you executed the command you willContinue reading “MongoDB Import / Export”

MongoDB Indexing

I am using Ruby and MongoDB in a project and I got today this Exception here: Mongo::OperationFailure (too much data for sort() with no index): The Problem was really that the searched field was not indexed. You can add an index like this: db.products.ensureIndex({name:1}); That means the attribute “name” on the “products” document get indexedContinue reading “MongoDB Indexing”

Useful MongoDB commands

How to install MongoDB on Mac OS X I showed already here: If everything is installed correctly, you can start the server process as root with this command: mongod and the client as no root with this command: mongo By default you are logged in into the “test” database. You can show all dbsContinue reading “Useful MongoDB commands”

Installing MongoDB on Mac OX X Lion

Today I tried to install mongodb via MacPorts on Mac OS X Lion. I got this error message: Error: Target returned: shell command failed (see log for details) Log for mongodb is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_mongodb/mongodb/main.log Error: Status 1 encountered during processing. To report a bug, see <; Maybe it is not the best idea toContinue reading “Installing MongoDB on Mac OX X Lion”