From 9002a919a5c77f7903a4edb9786b33e6deb97b21 Mon Sep 17 00:00:00 2001 From: casterlee Date: Sat, 1 Aug 2020 00:16:52 +0800 Subject: [PATCH] use unique index --- .gitignore | 2 ++ adapter.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7c6275..ef707d2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ .glide/ .idea/ +.vscode/ +vendor/ *.iml \ No newline at end of file diff --git a/adapter.go b/adapter.go index 2140a48..190a6fa 100644 --- a/adapter.go +++ b/adapter.go @@ -146,7 +146,8 @@ func (a *adapter) open(databaseName string) error { if _, err = collection.Indexes().CreateOne( context.Background(), mongo.IndexModel{ - Keys: keysDoc, + Keys: keysDoc, + Options: options.Index().SetUnique(true), }, ); err != nil { return err