Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
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.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório

0

This issue happens when you call find() before mongoose.connect() succeeds. Await mongoose.connect() before calling find().

over 4 years ago · Santiago Trujillo Relatório

0

Check if you are specifying some of the following options when connecting to MongoDB: useNewUrlParser, useUnifiedTopology, useFindAndModify, useCreateIndex. If you are, remove these from options object and try again.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda