root@mongodb-lab-01:~# cat test2.js Date() use admin; db.auth("santanaj","password") db.getUsers() use db01; db.mycoll.find() root@mongodb-lab-01:~# mongo < test2.js MongoDB shell version v3.4.4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.4 Thu Apr 27 2017 10:50:15 GMT+0200 (CEST) switched to db admin 1 [ { "_id" : "admin.santanaj", "user" : "santanaj", "db" : "admin", "roles" : [ { "role" : "root", "db" : "admin" } ] } ] switched to db db01 { "_id" : ObjectId("5901a8eaaaae00c4a0faa95a"), "ticket" : "SERVER-28956" } bye root@mongodb-lab-01:~#