-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexes.go
44 lines (41 loc) · 977 Bytes
/
indexes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func (a *app) EnsureIndexes() error {
{
seenItemsView := a.seenItems.Indexes()
_, err := seenItemsView.CreateMany(context.TODO(), []mongo.IndexModel{
{
Keys: bson.D{
{Key: "feed_id", Value: -1},
{Key: "guid", Value: -1},
},
Options: options.Index().SetName("already_notified_lookup").SetUnique(true),
},
})
if err != nil {
return err
}
}
{
usersView := a.users.Indexes()
_, err := usersView.CreateMany(context.TODO(), []mongo.IndexModel{
{
Keys: bson.D{{Key: "email", Value: -1}},
Options: options.Index().SetName("preexisting_email_lookup").SetUnique(true),
},
{
Keys: bson.D{{Key: "addr", Value: -1}},
Options: options.Index().SetName("address_based_lookup").SetUnique(true),
},
})
if err != nil {
return err
}
}
return nil
}