title: How to interact with MongoDB via shell in OpenShift Online 3 Dev Preview?
body: <p>I've got multiple issues with an application which I suspect are related to permissions on the database.  </p>
  
  <p>Everything seems locked down however and I can't complete basic commands such as <code>show dbs</code> in order to troubleshoot the problems further and "see" what I'm working with. I've been stuck on this for two days now and it's really frustrating.  </p>
  
  <p>I've tried this both from the online console and on local terminal, both with and without user credentials supplied at login:</p>
  
  <p><strong>Online Console</strong></p>
  
  <p><code>Console</code> > <code>MongoDB Service</code> > <code>Deployment</code> > <code>Pod</code> > <code>mongodb-1-vs19d</code> > <code>Terminal</code>:</p>
  
  <pre><code>sh-4.2$ mongo                                                                   
  MongoDB shell version: 2.6.9                                                    
  connecting to: test                                                             
  &gt; show dbs                                                                      
  2016-07-13T04:33:10.809-0400 listDatabases failed:{                             
          "ok" : 0,                                                               
          "errmsg" : "not authorized on admin to execute command { listDatabases: 
  1.0 }",                                                                         
          "code" : 13                                                             
  } at src/mongo/shell/mongo.js:47
  </code></pre>
  
  <p><strong>Local Terminal</strong></p>
  
  <pre><code>me@my-computer:~$ oc rsh mongodb-1-vs19d
  sh-4.2$ mongo
  MongoDB shell version: 2.6.9
  connecting to: test
  &gt; show dbs
  2016-07-13T04:35:06.449-0400 listDatabases failed:{
      "ok" : 0,
      "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
      "code" : 13
  } at src/mongo/shell/mongo.js:47
  </code></pre>
  
  <p><strong>Local Terminal With User Credentials</strong></p>
  
  <pre><code>me@my-computer:~$ oc rsh mongodb-1-vs19d
  sh-4.2$ mongo -u $MONGODB_USER -p $MONGODB_PASSWORD $MONGODB_DATABASE
  MongoDB shell version: 2.6.9
  connecting to: users
  &gt; show dbs
  2016-07-13T04:51:39.127-0400 listDatabases failed:{
      "ok" : 0,
      "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
      "code" : 13
  } at src/mongo/shell/mongo.js:47
  </code></pre>
  
  <p>Troubleshooting <code>envars</code> are correct:</p>
  
  <pre><code>me@my-computer:~$ oc env pods mongodb-1-vs19d --list
  # pods mongodb-1-vs19d, container mongodb
  MONGODB_USER=admin
  MONGODB_PASSWORD=secret
  MONGODB_DATABASE=users
  MONGODB_ADMIN_PASSWORD=very-secret
  </code></pre>
  
  <p>The database was created from local terminal with:</p>
  
  <pre><code>oc new-app mongodb-persistent -p MONGODB_USER=admin,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=very-secret
  </code></pre>
  
  <p>As per official docs:</p>
  
  <p><a href="https://docs.openshift.com/online/getting_started/beyond_the_basics.html#btb-provisioning-a-database" rel="nofollow">https://docs.openshift.com/online/getting_started/beyond_the_basics.html#btb-provisioning-a-database</a></p>
  
  <p><a href="https://docs.openshift.com/online/using_images/db_images/mongodb.html#running-mongodb-commands-in-containers" rel="nofollow">https://docs.openshift.com/online/using_images/db_images/mongodb.html#running-mongodb-commands-in-containers</a></p>