【发布时间】:2021-09-01 22:03:18
【问题描述】:
我正在学习猫鼬并决定运行这段代码
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test');
const personSchema = new mongoose.Schema({
name: String,
age: Number,
});
const Person = mongoose.model('Person', personSchema);
const person = new Person({
name: 'John',
age: 25,
});
person.save().then(()=> console.log('inserted'));
Person.find( function (err, docs) {
if(err){
console.log(err);
}else{
console.log(docs);
}
});
但是它似乎没有像我预期的那样工作(我想打印与模型 Person 相关的集合的每个文档)。相反,我收到了这个警告/错误:
(node:645135) UnhandledPromiseRejectionWarning: MongoInvalidArgumentError: Method "collection.find()" 在 Collection.find 中最多接受两个参数 ...
【问题讨论】: