Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

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

anifarm.findById("707876147324518400")

Official docs here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda