Warning
Experimental feature实验特性
This feature is experimental. MongoDB does not provide support for Snippets. This feature may be changed or removed at any time without prior notice.此功能是实验性的。MongoDB不支持代码段。此功能可能随时更改或删除,恕不另行通知。
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日志文件
npm Log FilesThe 如果你遇到问题,npm日志文件是一个很好的起点。日志文件的位置将根据npm log files are a good place to start if you encounter a problem. The log file location will vary depending on your npm installation. It will be something like:npm安装而有所不同。它将类似于:
/<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.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文件,删除代码段名称错误的行。
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. In this example, delete the highlighted line and the trailing comma from the line above.package.json文件以删除缺少的条目。在此示例中,删除上面行中突出显示的行和尾随逗号。
{
"dependencies": {
"@mongosh/snippet-analyze-schema": "^1.0.5",
"@mongosh/snippet-spawn-mongod": "^1.0.1",
"npm": "*",
"@<REGISTRY NAME>/bad-snippet-name": "^1.0.7"
}
}