gpt4 book ai didi

node.js - 方法 "collection.find()"最多接受两个参数

转载 作者:行者123 更新时间:2023-12-05 04:46:00 25 4
gpt4 key购买 nike

const roomSchema = new mongoose.Schema({
roomname: {
type: String,
required: true
},
users: {
type: Array,
required: true
},
createdDate: {
type: Date,
default: new Date()
},
admins: {
type: Array
},
groupType: {
type: String,
required: true
},
requests: {
type:Array
},
ip: {
type:String,
required:true
},
country:{
type:String,
required:true
}
});
const roomModel=mongoose.model('room',roomSchema)
const getUsersInaRoom=async ()=>{
const res = await roomModel.find({ 'roomname': 'room1' });
console.log(res);
}
getUsersInaRoom();

它抛出的错误是:

node:6123) UnhandledPromiseRejectionWarning: MongoInvalidArgumentError: Method "collection.find()" accepts at most two argumentsat Collection.find (/Users/macpro/Desktop/React/chat-using-socket/backend/node_modules/mongodb/lib/collection.js:238:19)

几分钟前它还可以完美运行,现在抛出上述错误。

最佳答案

新版本的 mongoose 似乎有问题。运行 npm rm mongoose 卸载当前版本,运行 npm i mongoose@5.13.8 安装之前的版本并重试。

关于node.js - 方法 "collection.find()"最多接受两个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68986598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com