安装:
连接mongodb:
数据库虽然安装并启动成功了,但我们需要连接数据库后才能使用数据库。怎么才能在 Node.js 中使用 MongoDB 呢?我们使用官方提供的 node-mongodb-native 驱动模块,打开 package.json,在 dependencies 中添加一行:
"mongodb": "1.4.15"
? ~ git:(master) ?cd ./Desktop/blog
? blog git:(master) ?npm install
? ~ git:(master) ? cd ./Desktop/blog ? blog git:(master) ? npm install > [email protected] install /Users/goyoo/Desktop/blog/node_modules/mongodb/node_modules/kerberos > (node-gyp rebuild 2> builderror.log) || (exit 0) / CXX(target) Release/obj.target/kerberos/lib/kerberos.o > [email protected] install /Users/goyoo/Desktop/blog/node_modules/mongodb/node_modules/bson > (node-gyp rebuild 2> builderror.log) || (exit 0) CXX(target) Release/obj.target/bson/ext/bson.o SOLINK_MODULE(target) Release/bson.node SOLINK_MODULE(target) Release/bson.node: Finished [email protected] node_modules/mongodb ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected]) ├── [email protected] └── [email protected] ([email protected]) ? blog git:(master) ?
时间: 2024-10-02 00:09:50