question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to switch database

See original GitHub issue

In the mongo shell, I can do like this:

use admin
db.auth('user','pass')
use test
db.find()

This means I pass the authurized then I can do everything.

My problem is how can I do the same work in mongoose, how can I switch db in mongonse?

Because I must enter the ADMIN db to authurize, and then chang to other db to my own manipulation

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:10

github_iconTop GitHub Comments

51reactions
naxmefycommented, Aug 29, 2014

other possible way is with query param in url

 mongodb://root:pass@localhost:27017/mydb?authSource=admin

look here -> Support AuthSource

12reactions
ghostcommented, Jun 21, 2013

Had problem to connect to a mongodb - coz the auth would bring me to a specific db like “admin” (standard). But how with mongoose? Only set the authSource inside of auth option…

var db = mongoose.createConnection(
  "localhost", 
  "myCostumDB", 
  "27010", 
  {
    user: "root",
    pass: "mypass",
    auth: {
      authSource: "admin" //<-- That is the Point.....
    }
  }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to switch databases in psql? - postgresql - Stack Overflow
Run psql in command line, it will switch to default database; psql anotherdb , it will switch to the db with the name...
Read more >
Listing and Switching Databases in PostgreSQL - Liquid Web
Step 1: Login to your Database · Step 2: Enter the PostgreSQL environment · Step 3: List Your PostgreSQL databases · Step 4:...
Read more >
Example of Postgres Switch Database - eduCBA
We can switch between the databases in PostgreSQL using \c or \connect metacommand, which creates a new connection and closes the current one....
Read more >
Switch databases in PostgreSQL with `\connect`
Postgres has a different way to switch databases, you do so using one of its meta-commands. Once you are in the Postgres terminal,...
Read more >
SWITCH - Database - Oracle Help Center
A SWITCH is equivalent to the SQL statement ALTER DATABASE RENAME FILE : the names of the files in the RMAN repository are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found