Docs HomeMongoDB Shell

Troubleshooting故障排除

Warning

Experimental feature实验特性

This feature is experimental. 此功能是实验性的。MongoDB does not provide support for Snippets. MongoDB不支持Snippets。This feature may be changed or removed at any time without prior notice.此功能可能随时更改或删除,恕不另行通知。

Bugs are not expected, however should you encounter one, please open an issue in the GitHub repository for this project.预计不会出现错误,但如果您遇到错误,请在GitHub存储库中打开此项目的问题。

The following sections provide troubleshooting suggestions.以下部分提供了故障排除建议。

View npm Log Files查看npm日志文件

The npm log files are a good place to start if you encounter a problem. 如果遇到问题,npm日志文件是一个很好的起点。The log file location will vary depending on your npm installation. 日志文件的位置将根据您的npm安装而有所不同。It will be something like:它将类似于:

/<NPM USER HOME>/.npm/_logs/2021-09-16T22_03_34_534Z-debug.log

When you locate the log files, check the most recent one.找到日志文件后,请检查最新的日志文件。

Non-specific Error Message非特定错误消息

Problem: mongosh returns a non-specific error message when you try to start the shell.mongosh在您尝试启动shell时返回一条非特定的错误消息。

Solution: Disable snippets, restart mongosh to continue debugging.:禁用snippets,重新启动mongosh以继续调试。

mongosh --nodb --eval 'config.set("snippetIndexSourceURLs", "")'

Error: Cannot find module

Problem: mongosh returns an error message like this when you try to start the shell:mongosh在尝试启动shell时返回如下错误消息:

Error: Cannot find module '/<PATH to USER HOME>/.mongodb/mongosh/snippets/node_modules/@<REGISTRY NAME>/bad-snippet-name'

The npm log file may have lines like these:npm日志文件可能有如下行:

36 error code ELSPROBLEMS
37 error missing: @<REGISTRY NAME>/bad-snippet-name@*, required by snippets@

Solution: Edit the ~/.mongodb/mongosh/snippets/package.json file to remove the line with the bad-snippet-name.:编辑~/.mongodb/mongosh/snippets/package.json文件以删除具有bad-snippet-name的行。

In this example, do not forget to delete the trailing comma from the line above as well.在本例中,也不要忘记删除上面一行的尾部逗号。

{
"dependencies": {
"@mongosh/snippet-analyze-schema": "^1.0.5",
"@mongosh/snippet-spawn-mongod": "^1.0.1",
"npm": "*",
"@<REGISTRY NAME>/bad-snippet-name": "^1.0.7"
}
}

Uninstalling a Snippet Fails卸载代码段失败

Problem: Uninstall fails, but the error message refers to a different snippet.:卸载失败,但错误消息引用了不同的代码段。

The following error message below is reformatted for readability:为了便于阅读,下面的错误消息已重新格式化:

Running uninstall...
Uncaught:
Error: Command failed: /usr/bin/mongosh
/root/.mongodb/mongosh/snippets/node_modules/npm/bin/npm-cli.js
--no-package-lock
--ignore-scripts
--registry=https://registry.npmjs.org uninstall
--save @mongosh/snippet-mongocompat with exit code 1: \
npm ERR! code E404 npm ERR! 404 Not Found
- GET https://registry.npmjs.org/@<REGISTRY NAME>%2fbad-snippet-name
- Not found
npm ERR! 404
npm ERR! 404 '@<REGISTRY NAME>/bad-snippet-namen@*' is not in this registry.

Solution: Edit the package.json file to remove the missing entry. :编辑package.json文件以删除丢失的条目。In this example, delete the highlighted line and the trailing comma from the line above.在本例中,删除上面一行中高亮显示的行和尾部逗号。

{
"dependencies": {
"@mongosh/snippet-analyze-schema": "^1.0.5",
"@mongosh/snippet-spawn-mongod": "^1.0.1",
"npm": "*",
"@<REGISTRY NAME>/bad-snippet-name": "^1.0.7"
}
}