美文网首页
mongoose入门手册

mongoose入门手册

作者: 一点金光 | 来源:发表于2018-09-19 17:44 被阅读0次

    管数据库

    # 连接
    # 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
    
    

    相关文章

      网友评论

          本文标题:mongoose入门手册

          本文链接:https://www.haomeiwen.com/subject/kkjqmftx.html