Web/GoLang

[golang] 몽고 빈값 체크

벨포트조던 2021. 8. 17.
반응형

https://dev-qa.com/946574/how-do-you-know-that-the-user-is-not-listed-in-the-database

 

How do you know that the user is not listed in the database? - IT & Development questions

I use the official library to work with mongodb. When registering a new user needs to know whether the id was before. However, if the database has no such IDs? method FindOne returns an error mongo: no documents in result How to separate error in the absen

dev-qa.com

 

 

 

if err != nil {
		if errors.Is(err, mongo.ErrNoDocuments) {
			return entity, err
		} else {
			return nil, err
		}
	}
반응형

댓글