[GODRIVER-730] Find does not return an error if there are no objects. Created: 20/Dec/18  Updated: 27/Oct/23  Resolved: 14/Jan/19

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: John Daniels Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ubuntu 18.04 (server&desktop)



 Description   

There is a call to find:

cursor, err := s.db.Collection(collectionNotification).Find(ctx, bson.M\{"terminal_id": bson.M{"$in": terminalList}, "status": status})
if err != nil {
 return err
}

In the case when the documents are not found, the error is not returned.
You have to do an additional check to handle the error.

if !cursor.Next(ctx) {
 return nil, mongo.ErrNoDocuments
}



 Comments   
Comment by Kristofer Brandow (Inactive) [ 04/Jan/19 ]

Hi pocoz,

Like the database/sql package, we only return an error when no documents are found in the case where you query for a single document, e.g. with FindOne. Finding no documents with a regular Find is not considered an error.

--Kris

Generated at Thu Feb 08 08:34:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.