in src/commands/importDocuments.ts [16:62]
export async function importDocuments(context: IActionContext, uris: vscode.Uri[] | undefined, collectionNode: MongoCollectionTreeItem | DocDBCollectionTreeItem | undefined): Promise<void> {
if (!uris) {
uris = await askForDocuments(context);
}
const ignoredUris: vscode.Uri[] = []; //account for https://github.com/Microsoft/vscode/issues/59782
uris = uris.filter((uri) => {
if (uri.fsPath.toLocaleLowerCase().endsWith('.json')) {
return true;
} else {
ignoredUris.push(uri);
return false;
}
});
if (ignoredUris.length) {
ext.outputChannel.appendLog(`Ignoring the following files which are not json:`);
ignoredUris.forEach(uri => ext.outputChannel.appendLine(`${uri.fsPath}`));
ext.outputChannel.show();
}
if (!collectionNode) {
collectionNode = <MongoCollectionTreeItem | DocDBCollectionTreeItem>await ext.tree.showTreeItemPicker([MongoCollectionTreeItem.contextValue, DocDBCollectionTreeItem.contextValue], context);
}
let result: string;
result = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Importing documents..."
},
async (progress) => {
uris = nonNullValue(uris, 'uris');
collectionNode = nonNullValue(collectionNode, 'collectionNode');
progress.report({ increment: 20, message: "Parsing documents for errors" });
const documents = await parseDocuments(uris);
progress.report({ increment: 30, message: "Parsed documents. Importing" });
if (collectionNode instanceof MongoCollectionTreeItem) {
result = await insertDocumentsIntoMongo(collectionNode, documents);
} else {
result = await insertDocumentsIntoDocdb(collectionNode, documents, uris);
}
progress.report({ increment: 50, message: "Finished importing" });
return result;
}
);
await collectionNode.refresh(context);
await vscode.window.showInformationMessage(result);
}