mongodb 中间件不进入
发布于 6 天前 作者 Jarvin-Guan 147 次浏览 来自 问答

const mongoose = require(‘mongoose’);

mongoose.connect(‘mongodb://192.168.99.100:32768/daai’);

let ChildSchema = new mongoose.Schema({ name: String, gender: Number, /* 0: female, 1: male */ head: {type: mongoose.Schema.Types.ObjectId, ref:‘Upload’}, psychicFactor: [{type: mongoose.Schema.Types.ObjectId, ref:‘PsychicFactor’}], birthDate: { year: Number, month: Number, day: Number }, user: {type: mongoose.Schema.Types.ObjectId, ref: ‘User’}, },{collection: ‘Child’});

var Child = mongoose.model(‘Child’, ChildSchema);

ChildSchema.pre(‘find’, function() { console.log(“进入”); next(); });

Child.find({_id:“571599ad0c81f39bff0e9ed1”}).exec(function(err,doc){ console.log(doc); });

只打印了doc,不打印进入

2 回复

代码格式化一下吧~到现在我也没用过mongoose- -

回到顶部