1、mongodb 启动的命令: mongod --dbpath=/data/db --port=27017
以守护进程的方式启动 :mongod --dbpath=/data/db --port=27017 --fork --logpath=/var/log/mongod.log
关闭mongodb指令:mongod --shutdown
2、编写node.js 操作mongodb代码
mongod.js
var mongoose = require("mongoose");
var uri = "mongodb://localhost/nodejs";
mongoose.connect(uri);
var BookSchema = new mongoose.Schema({
name:String,
author:String,
publishTime:Date
});
mongoose.model('Book',BookSchema);
3、用Node指令执行 mongod.js