mongodb官网
软件下载
如何启动服务?
D:\cd 安装路径\MongoDB\Server\3.6\bin
mongod --dbpath D:\安装路径\MongoDB\Server\3.6\data//在bin目录下,配置数据库地址
nodejs如何操作mongoose?
- 安装
npm install mongoose
- 引入
// Using Node.js `require()`
const mongoose = require('mongoose');
// Using ES6 imports
import mongoose from 'mongoose';
- 连接mongodb
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database');
- 通过schema接口创建模块
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var BlogPost = new Schema({
author : ObjectId,
title : String,
body : String,
date : Date
});