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

236
Visualizações
Mongoose findOne sending null

I am trying to edit a discord bot made in python (I stored data initially in python) and transferring it to javascript (node.js) and can't feature out while connecting to my old db why findOne giving me null while providing proper discord id.

Without anything inside
Code

anifarm.findOne();

Output

{
  _id: 707876147324518400,
  farmed: 17,
  ordered: 5,
  pimage: 'https://media.tenor.com/images/e830217a5d9926788ef25119955edc7f/tenor.gif',
  pstatus: 'I want you to be happy. I want you to laugh a lot. I don’t know what exactly I’ll be able to do for you, but I’ll always be by your side.',
  avg: 184,
  speed: 2,
  badges: [
    'https://cdn.discordapp.com/attachments/856137319149207563/856137435696332800/Black-and-Yellow-Gaming-Badge--unscreen.gif',
    'https://cdn.discordapp.com/attachments/856137319149207563/862219383866523688/Front-removebg-preview.png',    'https://cdn.discordapp.com/attachments/856137319149207563/862240758768599100/download-removebg-preview.png'
  ],
  setBadges: 'https://cdn.discordapp.com/attachments/856137319149207563/862240758768599100/download-removebg-preview.png'
}

With id inside
Code

anifarm.findOne({
    _id: 707876147324518400
});

Output

null

anifarm in the schema.
Decleared Schema

module.exports = mongoose.model('anifarm', new mongoose.Schema({
        _id: Number,
        farmed: {
            type: Number,
            default: 0
        },
        ordered: {
            type: Number,
            default: 0
        },
        pimage: {
            type: String,
            default: ""
        },
        pstatus: {
            type: String,
            default: ""
        },
        avg: {
            type: Number,
            default: 200
        },
        speed: {
            type: Number,
            default: 2
        },
        badges: {
            type: Array,
            default: []
        },
        setBadges: {
            type: String,
            default: ""
        }

    },
    {
        collection: 'anifarm',
        versionKey: false
    })
);

I cannot figure out what am I doing wrong. This problem also happens with .find()
Nothing inside find fetches everything by if I provide id it sends a empty array.
A Little help would be appreciated

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

For you problem use mongoose-long that should fix your problem.

This library will handle all long type data for mongoose since mongoose cannot handle long type data

about 4 years ago · Juan Pablo Isaza Relatório

0

you can't pass an id as a number, you will have to use ObjectId to convert the id to an instanceof ObjectId

Change your code like this

anifarm.findOne({
    _id: mongoose.Types.ObjectId(707876147324518400);
});
about 4 years ago · Juan Pablo Isaza Relatório

0

If you're querying by _id, use findById() instead.

anifarm.findById("707876147324518400")

Official docs here

about 4 years ago · Juan Pablo Isaza 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