require 'mongo' include Mongo db = MongoClient.new('/tmp/mongodb-27017.sock')['test'] db.authenticate('root','password') loop do db['test'].find_one end
If you examine the MongoDB log you will see that the client is constantly re-authenticating. If you do not use a unix socket, this does not occur.
mongod.log
2013-10-24T11:13:54.148-0400 [initandlisten] connection accepted from #182854 (2 connections now open) 2013-10-24T11:13:54.149-0400 [conn182854] authenticate db: test { authenticate: 1, user: "root", nonce: "d94390d6c9d741b6", key: "eadc6518d9eef3174fd6dcb15af00c8f" } 2013-10-24T11:13:54.149-0400 [conn182854] end connection (1 connection now open) 2013-10-24T11:13:54.149-0400 [initandlisten] connection accepted from #182855 (2 connections now open) 2013-10-24T11:13:54.149-0400 [conn182855] authenticate db: test { authenticate: 1, user: "root", nonce: "17d49f444d4d901e", key: "d15d97511be6b659f08c802562a14afb" } 2013-10-24T11:13:54.150-0400 [conn182855] end connection (1 connection now open) 2013-10-24T11:13:54.150-0400 [initandlisten] connection accepted from #182856 (2 connections now open) 2013-10-24T11:13:54.150-0400 [conn182856] authenticate db: test { authenticate: 1, user: "root", nonce: "b9288c7111ce2817", key: "f410a2de62baebb2c7eff9723117596f" } 2013-10-24T11:13:54.150-0400 [conn182856] end connection (1 connection now open) 2013-10-24T11:13:54.150-0400 [initandlisten] connection accepted from #182857 (2 connections now open) 2013-10-24T11:13:54.151-0400 [conn182857] authenticate db: test { authenticate: 1, user: "root", nonce: "b5e34a6cc285e43", key: "c4d083b795197184ed1b247bd547ab2f" } 2013-10-24T11:13:54.151-0400 [conn182857] end connection (1 connection now open) 2013-10-24T11:13:54.151-0400 [initandlisten] connection accepted from #182858 (2 connections now open) 2013-10-24T11:13:54.152-0400 [conn182858] authenticate db: test { authenticate: 1, user: "root", nonce: "5a5313a685f7a5a2", key: "9a1cacd30f39294a9a1aee6629a2c50c" } 2013-10-24T11:13:54.152-0400 [conn182858] end connection (1 connection now open) 2013-10-24T11:13:54.152-0400 [initandlisten] connection accepted from #182859 (2 connections now open) 2013-10-24T11:13:54.153-0400 [conn182859] authenticate db: test { authenticate: 1, user: "root", nonce: "7f53bd6a311374f5", key: "d66b3a123b3b6790e3bf124083e08ade" } 2013-10-24T11:13:54.153-0400 [conn182859] end connection (1 connection now open) 2013-10-24T11:13:54.153-0400 [initandlisten] connection accepted from #182860 (2 connections now open) 2013-10-24T11:13:54.154-0400 [conn182860] authenticate db: test { authenticate: 1, user: "root", nonce: "92b9fa15e02ea578", key: "e042b4286233a141ff714f7833ba1b38" } 2013-10-24T11:13:54.154-0400 [conn182860] end connection (1 connection now open) 2013-10-24T11:13:54.154-0400 [initandlisten] connection accepted from #182861 (2 connections now open) 2013-10-24T11:13:54.155-0400 [conn182861] authenticate db: test { authenticate: 1, user: "root", nonce: "d2e83eda71fb229", key: "c8a887797e443da4cb338ed7fa8de56a" }