nodejs之egg框架mongoose应用

发布时间:2020-07-26 14:29:50 作者:小涴熊
来源:网络 阅读:606

config/plugin.js

mongoose: {
        enable: true,
        package: 'egg-mongoose'
}

config/config.default.js

config.mongoose = {
        client: {
            url: 'mongodb://devuser:devuser123@127.0.0.1:27017/db_co_assist',
            options: {}
        }
 };

app/model/test.js

'use strict';
module.exports = app => {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    const TestSchema = new Schema({
        name: {
            type: String,
        },
        age: {
            type: Number,
        },
        __v: {
            type: Number
        }
    });
    return mongoose.model('Test', TestSchema, 'test');
};

更新文档

let conditions = {
            _id: '5d4287eb6884ad1c30cc97b1'
        };
        let update = {
            name: '测试8888888888888',
            age: 100,
            __v: 100102
        };
        this.ctx.model.Test.update(conditions, update, function (err) {
            if (err) {
                console.error(err);
            }
        });
推荐阅读:
  1. nodejs之egg框架整合ejs模板
  2. nodejs之egg框架mysql应用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nodejs egg mongoose

上一篇:MySQL5.6.44 [Err] 1067 - Inval

下一篇:webpack优化——定义“生产”环境

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》