[SERVER-6356] Provide a database stack in shell Created: 09/Jul/12 Updated: 17/Jul/20 Resolved: 17/Jul/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Doug Hudson | Assignee: | DO NOT USE - Backlog - Platform Team |
| Resolution: | Won't Do | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
It's common to jump between a number of databases in the shell. Having to type (even remember) the full name every time can be time consuming. It would be helpful for the shell to maintain a simple stack to jump between databases quickly. e.g. // Push another DB onto stack (and change to it) There is a related feature request to tab-complete database names in the shell. With these two features, the efficiency of a mongodb shell session could be enhanced. |
| Comments |
| Comment by Jessica Sigafoos [ 17/Jul/20 ] | |||||||||
|
This is not a current priority for the new shell. The new shell can potentially be extended with a user-defined function that does this. | |||||||||
| Comment by Doug Hudson [ 05/Sep/12 ] | |||||||||
|
If anyone ever stumbles across this, I ended up putting together something that adds this functionality to the mongo shell. It overrides (optionally) 'use dbname', and adds pushdb, popdb, dbs, cleardbs, with some other goodies that make my shell experience and db navigation more fluid. | |||||||||
| Comment by Doug Hudson [ 09/Jul/12 ] | |||||||||
|
Sure, but there are other aspects of using a "current" database. We do a lot of collection changes, and "show collections" is probably my most frequently used command. getCollectionNames() is there of course, but having the context of the current db has other advantages, rather than maintaining and referencing pointers to multiple DBs. I appreciate it's quite a specific request; I will just add some stuff to my .mongorc.js to do this. Thanks! | |||||||||
| Comment by Randolph Tan [ 09/Jul/12 ] | |||||||||
|
db is actually an object representing the current database selected, so you can store into a variable to make it easy switching between multiple databases. Example:
|