nodejs之egg框架mongoose应用

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);
            }
        });
上一篇:axios显示数据库数据


下一篇:javascript – 回调不是mongoose.find({})中的函数