inserisce tutti i docs su mongo.

This commit is contained in:
Miki 2015-11-25 09:05:14 +01:00
parent 588244794c
commit 5656565440
2 changed files with 29 additions and 27 deletions

View file

@ -4,7 +4,7 @@ package main
import (
"fmt"
// "github.com/garyburd/redigo/redis"
"gopkg.in/mgo.v2/bson"
// "gopkg.in/mgo.v2/bson"
"log"
"strconv"
"strings"
@ -83,33 +83,35 @@ func consumer(id int) {
Date: time.Unix(date, 0),
}
// cerca se esiste gia' un documento con gli stessi User & Date
docfind := []Ips{}
iter := dbs.ll.Find(bson.M{"user": prod.user, "date": time.Unix(date, 0)}).Select(bson.M{"ip": 1, "_id": 0}).Iter()
iter.All(&docfind)
if len(docfind) > 0 {
count.AddDuplicate()
if !contains(docfind, ml.Ip) {
fmt.Printf("Insert != IP for same date: user=%s - date=%s\n - newip=%s - oldip=%s\n", ml.User, ml.Date, docfind, ml.Ip)
// inserisce il login su Mongodb se gli IP sono !=
err := dbs.ll.Insert(ml)
if err != nil {
log.Printf("Insert error: %+v - %s\n", err, cons.user)
count.AddErr()
cons.error = true
continue
/*
docfind := []Ips{}
iter := dbs.ll.Find(bson.M{"user": prod.user, "date": time.Unix(date, 0)}).Select(bson.M{"ip": 1, "_id": 0}).Iter()
iter.All(&docfind)
if len(docfind) > 0 {
count.AddDuplicate()
if !contains(docfind, ml.Ip) {
fmt.Printf("Insert != IP for same date: user=%s - date=%s\n - newip=%s - oldip=%s\n", ml.User, ml.Date, docfind, ml.Ip)
// inserisce il login su Mongodb se gli IP sono !=
err := dbs.ll.Insert(ml)
if err != nil {
log.Printf("Insert error: %+v - %s\n", err, cons.user)
count.AddErr()
cons.error = true
continue
}
}
}
} else {
// inserisce il login su Mongodb
err := dbs.ll.Insert(ml)
if err != nil {
log.Printf("Insert error: %+v - %s\n", err, cons.user)
count.AddErr()
cons.error = true
continue
}
} else {
*/
// inserisce il login su Mongodb
err = dbs.ll.Insert(ml)
if err != nil {
log.Printf("Insert error: %+v - %s\n", err, cons.user)
count.AddErr()
cons.error = true
continue
}
iter.Close()
// }
// iter.Close()
if opts.Debug {
log.Printf("%+v - %+v\n", ml)

View file

@ -11,7 +11,7 @@ import (
)
const (
_VERSION = "v2.3.0"
_VERSION = "v2.3.1"
)
var (