mongodb 中间件不进入
发布于 9 年前 作者 Jarvin-Guan 4582 次浏览 最后一次编辑是 8 年前 来自 问答
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,不打印进入

管理员温馨提示:发帖前请先简单学一下Markdown语法

2 回复

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

@DevinXian 这是测试代码~

回到顶部