aboutsummaryrefslogtreecommitdiff
path: root/indexes.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-06-03 13:59:49 +0300
committerAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-06-03 13:59:49 +0300
commitc36227104708bf48c95d2b61ba9176370eb0baf5 (patch)
tree47e0a0373956556955f1dcfb8f00421a6c714025 /indexes.go
parent2f4b6e90597784a8a7c01027e0ff5c6b69634a96 (diff)
Store objects on single collections (overpass like json)HEADmaster
Filter deleted objects
Diffstat (limited to 'indexes.go')
-rw-r--r--indexes.go58
1 files changed, 3 insertions, 55 deletions
diff --git a/indexes.go b/indexes.go
index d8dbb32..fb07886 100644
--- a/indexes.go
+++ b/indexes.go
@@ -2,7 +2,6 @@ package main
import (
"context"
- "log"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@@ -11,58 +10,9 @@ import (
func createIndexes(db *mongo.Database) error {
opts := options.CreateIndexes().SetMaxTime(1000)
- nodes := db.Collection("nodes")
- log.Println("creating indexes for nodes")
- created, err := nodes.Indexes().CreateMany(context.Background(), []mongo.IndexModel{
+ nodes := db.Collection("objects")
+ _, err := nodes.Indexes().CreateMany(context.Background(), []mongo.IndexModel{
{
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}, {"version", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
- Keys: bsonx.Doc{{"tags", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true),
- },
- }, opts)
- if err != nil {
- return err
- }
- log.Println(created)
- log.Println("creating geoindexes for nodes")
- if err := geoIndex(nodes, "location"); err != nil {
- return err
- }
-
- log.Println("creating indexes for ways")
- ways := db.Collection("ways")
- created, err = ways.Indexes().CreateMany(context.Background(), []mongo.IndexModel{
- {
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}, {"version", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
- Keys: bsonx.Doc{{"tags", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true),
- },
- }, opts)
- if err != nil {
- return err
- }
- log.Println(created)
-
- relations := db.Collection("relations")
- log.Println("creating geoindexes for relations")
- created, err = relations.Indexes().CreateMany(context.Background(), []mongo.IndexModel{
- {
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
- Keys: bsonx.Doc{{"osm_id", bsonx.Int32(-1)}, {"version", bsonx.Int32(-1)}},
- Options: (options.Index()).SetBackground(true).SetSparse(true).SetUnique(false),
- }, {
Keys: bsonx.Doc{{"tags", bsonx.Int32(-1)}},
Options: (options.Index()).SetBackground(true).SetSparse(true),
},
@@ -74,11 +24,9 @@ func createIndexes(db *mongo.Database) error {
if err != nil {
return err
}
- log.Println(created)
- if err := geoIndex(relations, "members.coords"); err != nil {
+ if err := geoIndex(nodes, "location"); err != nil {
return err
}
- log.Println("indexes created")
return nil
}