如何检查你的 Mongoose 版本
¥How to Check Your Mongoose Version
要检查你在 Node.js 中使用的 Mongoose 版本,请打印 mongoose.version
property,如下所示。
¥To check what version of Mongoose you are using in Node.js, print out the mongoose.version
property as follows.
const mongoose = require('mongoose');
console.log(mongoose.version); // '7.x.x'
我们建议从 Node.js 打印 Mongoose 版本,因为这样可以更好地处理安装了多个版本的 Mongoose 的情况。你还可以使用 Node.js 的 -e
标志从终端执行上述逻辑,如下所示。
¥We recommend printing the Mongoose version from Node.js, because that better handles cases where you have multiple versions of Mongoose installed.
You can also execute the above logic from your terminal using Node.js' -e
flag as follows.
# Prints current Mongoose version, e.g. 7.0.3
node -e "console.log(require('mongoose').version)"
使用 npm list
¥Using npm list
你也可以使用 npm list
来 获取 Mongoose npm 包的已安装版本。
¥You can also get the installed version of the Mongoose npm package using npm list
.
$ npm list mongoose
test@ /path/to/test
└── mongoose@7.0.3
npm list
很有用,因为它可以识别你是否安装了多个版本的 Mongoose。
¥npm list
is helpful because it can identify if you have multiple versions of Mongoose installed.
其他包管理器也支持类似的功能:
¥Other package managers also support similar functions: