管数据库
# 连接
# https://www.cnblogs.com/BlingSun/p/7903520.html
const mongoose = require('mongoose')
const DB_URL = ['dockerized_mongo', 'localhost']
const mongoUrl = process.env.NODE_ENV === 'docker-development' ? DB_URL[0] : DB_URL[1]
mongoose.connect(`mongodb://${mongoUrl}/mmfblog_v2`)
mongoose.Promise = global.Promise
module.exports = mongoose
# 断开
集合管理
# 创建
const mongoose = require('../mongoose')
const Schema = mongoose.Schema
const AdminSchema = new Schema({
username: String,
email: String,
password: String,
creat_date: String,
update_date: String,
is_delete: Number,
timestamp: Number
})
const Admin = mongoose.model('Admin', AdminSchema)
module.exports = Admin
文档管理
对照tp5
模型管理
# 创建模型
const mongoose = require('../mongoose')
const Schema = mongoose.Schema
const AdminSchema = new Schema({
username: String,
email: String,
password: String,
creat_date: String,
update_date: String,
is_delete: Number,
timestamp: Number
})
//模实例化
const Admin = mongoose.model('Admin', AdminSchema)
module.exports = Admin
网友评论