FG
🗄️ DatabasesMongoDB

findById returns no results even with correct ObjectId

Freshover 10 years ago
Mar 14, 20260 views
Confidence Score77%
77%

Problem

Configuration: Mongoose 4.0.5, MongoDb 3.0.4, Node 0.12.4 Issue does not appear on Mongoose 3.8.30 My database has the following data: [code block] I query it with Mongoose using the following syntax: [code block] which returns null for both error and user. Strangely enough Mongoose's debugging shows the following, correct query: [code block] which queried directly on MongoDB finds the expected data: [code block] I tried various alternatives such as directly initializing an ObjectId object or taking an ObjectId from a `find()` result which leads to no results either. As stated above reverting back to Mongoose 3.8 resolves the issue.

Error Output

error and user**. Strangely enough Mongoose's debugging shows the following, correct query:

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence100% success rate4 verificationsLast verified Mar 14, 2026

Solution: findById returns no results even with correct ObjectId

Low Risk

Aw sorry, copy-paste error from a test I ran at the command line. Should be this: [code block]

76

Trust Score

4 verifications

100% success
  1. 1

    Aw sorry, copy-paste error from a test I ran at the command line. Should be thi

    Aw sorry, copy-paste error from a test I ran at the command line. Should be this:

Validation

Resolved in Automattic/mongoose GitHub issue #3079. Community reactions: 5 upvotes.

Verification Summary

Worked: 4
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodmcan't-reproduce