Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method "collection.find()" accepts at most two arguments

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();

The error it throws is:

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

It used to work perfectly a few minutes ago, now throws the above error.

like image 534
Santosh Jugjali Avatar asked May 19 '26 06:05

Santosh Jugjali


1 Answers

There seems to be an issue with the new version of mongoose. Run npm rm mongoose to uninstall the current version, npm i [email protected] to install the previous one and try again.

like image 183
Kirill Avatar answered May 20 '26 20:05

Kirill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!