FG
💻 Software🗄️ Databases

.findOne(undefined) returns first item in the database instead of undefined

Freshalmost 6 years ago
Mar 14, 20260 views
Confidence Score78%
78%

Problem

Issue type: [ ] question [x] bug report [ ] feature request [ ] documentation issue Database system/driver: [ ] `cordova` [ ] `mongodb` [ ] `mssql` [ ] `mysql` / `mariadb` [ ] `oracle` [x ] `postgres` [ ] `sqlite` [ ] `sqljs` [ ] `react-native` [ ] `expo` TypeORM version: [x] `latest` [ ] `@next` [ ] `0.x.x` (or put your version here) Steps to reproduce or a small repository showing the problem: [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence90% success rate8 verificationsLast verified Mar 14, 2026

Solution: .findOne(undefined) returns first item in the database instead of undefined

Low Risk

> But there are no conditions (`undefined`) and I think if there is no condition we have to return first entity like from `User.findOne({});` No, you except same behavior as SQL [code block] return empty row not first entity.

76

Trust Score

8 verifications

90% success
  1. 1

    > But there are no conditions (`undefined`) and I think if there is no condition

    > But there are no conditions (`undefined`) and I think if there is no condition we have to return first entity like from `User.findOne({});`

  2. 2

    No, you except same behavior as SQL

    [code block] return empty row not first entity.

Validation

Resolved in typeorm/typeorm GitHub issue #2500. Community reactions: 51 upvotes.

Verification Summary

Worked: 8
Partial: 1
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescriptdiscussioncomp:-find-options