Only use local port as default Mongo connection if running (#713)

This commit is contained in:
Stephen Weatherford (MSFT) 2018-06-25 15:27:46 -07:00 коммит произвёл GitHub
Родитель aa550d173c
Коммит 76f6874f08
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 17 добавлений и 3 удалений

1
.vscode/extensions.json поставляемый
Просмотреть файл

@ -2,7 +2,6 @@
"recommendations": [
"eg2.tslint",
"ms-vscode.azure-account",
"DavidAnson.vscode-markdownlint",
"mike-lischke.vscode-antlr4"
]
}

Просмотреть файл

@ -32,7 +32,7 @@ You will now find us by clicking in the new Azure view container instead of the
## Mongo Scrapbooks
### Run Mongo Commands with Rich Intellisense
- View your MongoDB database account by [signing in to Azure](#managing-azure-subscriptions) or attaching with a connection string
- View your MongoDB database account by [signing in to Azure](#managing-azure-subscriptions) or using "Attach Database Account" to connect via a connection string
- Optionally configure the setting `mongo.shell.path` if your mongo executable is not already on your system's PATH (many of the common commands have built-in support and do not require the Mongo shell to be installed - see [Prerequisites](#prerequisites))
- Click on "New Mongo Scrapbook" in the tree title bar
- Click on "Connect to a database" to indicate which database to run the commands against

Просмотреть файл

@ -25,6 +25,8 @@ interface IPersistedAccount {
export const AttachedAccountSuffix: string = 'Attached';
export const MONGO_CONNECTION_EXPECTED: string = 'Connection string must start with "mongodb://" or "mongodb+srv://"';
const localMongoConnectionString: string = 'mongodb://127.0.0.1:27017';
export class AttachedAccountsTreeItem implements IAzureParentTreeItem {
public static contextValue: string = 'cosmosDBAttachedAccounts';
public readonly contextValue: string = AttachedAccountsTreeItem.contextValue;
@ -94,6 +96,16 @@ export class AttachedAccountsTreeItem implements IAzureParentTreeItem {
}
}
private async canConnectToLocalMongoDB(): Promise<boolean> {
try {
let db = await MongoClient.connect(localMongoConnectionString);
db.close();
return true;
} catch (error) {
return false;
}
}
public async attachNewAccount(): Promise<void> {
const defaultExperiencePick = await vscode.window.showQuickPick(getExperienceQuickPicks(), { placeHolder: "Select a Database Account API...", ignoreFocusOut: true });
if (defaultExperiencePick) {
@ -102,7 +114,10 @@ export class AttachedAccountsTreeItem implements IAzureParentTreeItem {
let defaultValue: string;
let validateInput: (value: string) => string | undefined | null;
if (defaultExperience.api === API.MongoDB) {
defaultValue = placeholder = 'mongodb://127.0.0.1:27017';
placeholder = 'mongodb://host:port';
if (await this.canConnectToLocalMongoDB()) {
defaultValue = placeholder = localMongoConnectionString;
}
validateInput = AttachedAccountsTreeItem.validateMongoConnectionString;
} else {
placeholder = 'AccountEndpoint=...;AccountKey=...';