Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
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 answers
Answer question

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 Report

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 Report

0

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

anifarm.findById("707876147324518400")

Official docs here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!