Projekat

Općenito

Profil

Podrška #20718 » main.go

Ernad Husremović, 01.07.2010 15:33

 
package main

import (
"mongo"
"fmt"
"strconv"
)


func main() {
SayHello("poč-početak")
conn, _ := mongo.ConnectAt("127.0.0.1", 27017)
collection := conn.GetDB("test").GetCollection("test_collection")

/*
var tmp_str string
tmp_str = "doc" + strconv.Itoa(1)
doc, _ := mongo.Marshal(map[string]string{
"_id": tmp_str,
"title": "A Mongo document",
"content": "Testing, 1. 2. 3.",
})
collection.Insert(doc)


for i:=2; i<100; i++ {
tmp_str = "doc" + strconv.Itoa(i)
doc, _ = mongo.Marshal(map[string]string{
"_id": tmp_str,
"title": "A Mongo document " + tmp_str,
"content": "Testing, 1. 2. 3. " + tmp_str,
})
collection.Insert(doc)
fmt.Printf("tmp_str = %s\n", tmp_str)
}
*/

query, _ := mongo.Marshal( map[string]string{ "_id": "doc1"} )
got, _ := collection.FindOne(query)
if got.Get("_id").String() == "doc1" {
SayHello("našao")
}

query, _ = mongo.Marshal( map[string]string{} )
cnt, _ := collection.Count(query)
fmt.Printf("count = %d\n", cnt)

ret, _:= collection.FindAll(query)
for i:=1; i<100; i++ {

doc, _ := ret.GetNext()

//tmp_str = doc.Get("_id").String()

//fmt.Printf("value = %s\n", tmp_str )
fmt.Printf("value = %s#\n", doc.Get("_id").String() )
}

query, _ = mongo.Marshal( map[string]string{ "_id": "doc"+strconv.Itoa(3) } )
got, _ = collection.FindOne(query)

if got.Get("_id").String() == "doc3" {
SayHello("našao cutri")
}


//collection.Drop()
//SayHello("dropped\n")
}


func SayHello(str string) {
fmt.Printf("%s\n", str)
}
(1-1/2)