From ff7ee4fc116b10374e1af0509191ed3c1300c1a2 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 10 Nov 2021 16:40:11 +0700 Subject: [PATCH] check err is not found --- error.go | 12 ++++++++++++ go.mod | 2 +- go.sum | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 error.go diff --git a/error.go b/error.go new file mode 100644 index 0000000..fd0445b --- /dev/null +++ b/error.go @@ -0,0 +1,12 @@ +package mongodb + +import ( + "errors" + + "go.mongodb.org/mongo-driver/mongo" +) + +// IsErrNotFound check err is not found document +func IsErrNotFound(err error) bool { + return errors.Is(err, mongo.ErrNoDocuments) +} diff --git a/go.mod b/go.mod index 8ca4092..176dc29 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,5 @@ go 1.16 require ( github.com/logrusorgru/aurora v2.0.3+incompatible go.mongodb.org/mongo-driver v1.7.1 - golang.org/x/text v0.3.7 // indirect + golang.org/x/text v0.3.7 ) diff --git a/go.sum b/go.sum index e87e9d4..037826c 100644 --- a/go.sum +++ b/go.sum @@ -101,7 +101,6 @@ golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -- 2.34.1