// GoogleNewsFindIfExist check google news current data if exist before insert
func GoogleNewsFindIfExist(URL string, sc *mongodb.Session) bool {
	c := sc.DB(Db).C(googleNewsCollection)

	var result map[string]interface{}
	c.Find(bson.M{"url": URL}).One(&result)
	if result["url"] != nil && result["url"] != URL {
		return false
	}
	return true
}
// GetDatabaseStatus returns stats for a given database
func GetDatabaseStatus(session *mgo.Session, db string) *DatabaseStatus {
	dbStatus := &DatabaseStatus{}
	err := session.DB(db).Run(bson.D{{"dbStats", 1}, {"scale", 1}}, &dbStatus)
	if err != nil {
		glog.Error(err)
		return nil
	}

	return dbStatus
}
예제 #3
1
func TestConn(t *testing.T) {
	fmt.Println(MInit("mongodb://127.0.0.1:27017/test", "test", "t"))
	for {
		var s *mgo.Session = GetMConn("t")
		e := []map[string]interface{}{}
		s.DB("admin").C("system.users").Find(bson.M{}).All(&e)
		b, _ := json.Marshal(e)
		fmt.Println(string(b))
		time.Sleep(time.Second * 5)
	}
}
func GetDatabase(databaseHost string) (database.Interface, error) {
	var session *mgo.Session
	var err error

	if session, err = getSession(databaseHost); err != nil {
		return nil, err
	}

	database := &database.MongoDB{Collection: session.DB("steamfetcher").C("games")}
	database.SetSession(session)

	return database, nil
}
예제 #5
0
파일: main.go 프로젝트: shutej/namestats
func add(session *mgo.Session, gender models.Gender, record Record) {
	c := session.DB("").C(models.Collection)
	c.EnsureIndex(mgo.Index{
		Key:    []string{"name", "gender"},
		Unique: true,
	})

	name := &models.Name{}
	c.Find(bson.M{"name": record.Name, "gender": gender}).One(&name)
	if name.Id == "" {
		name.Id = bson.NewObjectId()
		name.Name = record.Name
		name.Gender = gender
	}
	name.Rank.Set(record.Year, record.Rank)
	name.Count.Set(record.Year, record.Count)
	c.UpsertId(name.Id, bson.M{"$set": name})
}
예제 #6
0
파일: mongo.go 프로젝트: iwarsong/bearded
// Remove testing database and close session
func RandomTestMongoDown(session *mgo.Session, dbName string) {
	session.DB(dbName).DropDatabase()
	session.Close()
}
예제 #7
0
파일: models.go 프로젝트: feimyy/revmgo
func Collection(s *mgo.Session) *mgo.Collection {
	return s.DB("test").C("books")
}
예제 #8
0
func GetDb(se *mgo.Session) *mgo.Database {
	return se.DB(DbCfg.Name)
}