简体   繁体   English

无法在使用 Express 和 Azure Cosmos DB 的 Angular 应用程序中配置 MongoDB

[英]Unable to configure MongoDB in Angular application that is using Express and Azure Cosmos DB

I am facing strange issue in configuring and using Azure CosmosDB MongoDB Api in angular application, the configuration and code is referred from https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-develop-mongodb-nodejs-part2 and https://johnpapa.net/angular-cosmosdb-1/ , though i was able to configure and run application with express when i am trying to configure and install Mongoose node module getting series of errors: I am facing strange issue in configuring and using Azure CosmosDB MongoDB Api in angular application, the configuration and code is referred from https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-develop-mongodb- nodejs-part2https://johnpapa.net/angular-cosmosdb-1/ ,尽管当我尝试配置和安装 Mongoose 节点模块时,我能够使用 express 配置和运行应用程序出现一系列错误:

1) Cannot find module 'mongodb-extjson 2) Cannot find module 'bson-ext' 3) ENOENT: no such file or directory, access 'XXX\node_modules\bson-ext\lib\package.json 1)找不到模块'mongodb-extjson' 2)找不到模块'bson-ext' 3)ENOENT:没有这样的文件或目录,访问'XXX\node_modules\bson-ext\lib\package.json

I have tried re installing packages but no success.我尝试重新安装软件包但没有成功。

I am using Angular version 10 with mongoose version 5.11.14 i am getting error at compile time when trying to run it from vs code and trying to launch server/index.js on port 3000.我正在使用 Angular 版本 10 和 mongoose 版本 5.11.14 我在尝试从 vs 代码运行它并尝试在端口 3000 上启动 server/index.js 时在编译时出错。

Your help is greatly appriciated.非常感谢您的帮助。

You are getting 1 and 2 because the MongoDB driver checks for optional requirements during initialization.您得到 1 和 2 是因为 MongoDB 驱动程序在初始化期间检查可选要求。 You can F5 past them in VS Code.您可以在 VS Code 中按 F5 跳过它们。 Or install them like so:或者像这样安装它们:

node install mongodb-extjson
node install bson-ext

Number 3 is also due to an exception during startup. 3 号也是由于启动过程中的异常。 I have no clue to why this is missing but if you want to skip initial throws in the debugger you can start without debugging first and then "attach" to it.我不知道为什么会丢失它,但如果你想跳过调试器中的初始抛出,你可以先不调试就开始,然后“附加”到它。 Like so:像这样:

node --inspect --nolazy server/index.js

To attach to node with VSCode, make sure you have something like this in your.vscode\launch.json:要使用 VSCode 附加到节点,请确保在 your.vscode\launch.json 中有类似的内容:

{
    "name": "Docker: Attach to Node",
    "type": "node",
    "request": "attach",
    "port": 9229,
    "address": "localhost",
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/",
    "protocol": "inspector"
 }

Many node modules test things at startup by throwing and catching.许多节点模块在启动时通过抛出和捕获来测试事物。 For example:例如:

var hasStacks = false;
try {
    throw new Error();
} catch (e) {
    hasStacks = !!e.stack;
}

...and this leads to break in VS Code debugger. ...这会导致 VS Code 调试器中断。 So you might want to attach (ie press run "Docker: Attach to Node" after a few seconds.所以你可能想要附加(即在几秒钟后按运行“Docker:附加到节点”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM