Jason J
2018-06-14 03:20:43 UTC
I'm a noob learning both Go and ArangoDB. Both of which I'm enjoying
working with. However, I've very quickly came to a problem. My practice
code is failing and I don't understand ArangoDB enough to know why.
var DB driver.Database
func InitDB(){
fmt.Println("Init: DB start")
driver.WithStack = errors.WithStack
driver.Cause = errors.Cause
fmt.Println("Init: DB config")
// connect configuration
conn, err := http.NewConnection(http.ConnectionConfig{
Endpoints: []string{"http://localhost:8529"},
})
// check for error
if err != nil {
// Handle error
log.Fatalf("Failed to create HTTP connection: %v", err)
}
fmt.Println("Init: DB Client")
// create client connection
client, err := driver.NewClient(driver.ClientConfig{
Connection: conn,
})
if err != nil {
// Handle error
}
fmt.Println("Init: DB Connect to database")
// Open open database and store on DB
DB, err := client.Database(nil, "mydb")
if err != nil {
// Handle error
fmt.Printf("Database has error, %s", err)
}
fmt.Println("Init: Connected to Database :)")
found, err := DB.CollectionExists(nil, "character")
_ = found
if err != nil {
// handle error
fmt.Printf("Collection has error, %s \n", err)
} else {
fmt.Printf("Collection exists\n")
}
// sample
col, err := DB.Collection(nil, "character")
_ = col
if err != nil {
// Handle error
fmt.Printf("Collection has error, %s \n", err)
}
Here is my log out put
Init: DB start
Init: DB config
Init: DB Client
Init: DB Connect to database
Init: Connected to Dateabase :)
Collection exists
Collection has error, collection not found
I don't understand why the test for a collection seems ok, but when I try
to get the collection there is an error.
working with. However, I've very quickly came to a problem. My practice
code is failing and I don't understand ArangoDB enough to know why.
var DB driver.Database
func InitDB(){
fmt.Println("Init: DB start")
driver.WithStack = errors.WithStack
driver.Cause = errors.Cause
fmt.Println("Init: DB config")
// connect configuration
conn, err := http.NewConnection(http.ConnectionConfig{
Endpoints: []string{"http://localhost:8529"},
})
// check for error
if err != nil {
// Handle error
log.Fatalf("Failed to create HTTP connection: %v", err)
}
fmt.Println("Init: DB Client")
// create client connection
client, err := driver.NewClient(driver.ClientConfig{
Connection: conn,
})
if err != nil {
// Handle error
}
fmt.Println("Init: DB Connect to database")
// Open open database and store on DB
DB, err := client.Database(nil, "mydb")
if err != nil {
// Handle error
fmt.Printf("Database has error, %s", err)
}
fmt.Println("Init: Connected to Database :)")
found, err := DB.CollectionExists(nil, "character")
_ = found
if err != nil {
// handle error
fmt.Printf("Collection has error, %s \n", err)
} else {
fmt.Printf("Collection exists\n")
}
// sample
col, err := DB.Collection(nil, "character")
_ = col
if err != nil {
// Handle error
fmt.Printf("Collection has error, %s \n", err)
}
Here is my log out put
Init: DB start
Init: DB config
Init: DB Client
Init: DB Connect to database
Init: Connected to Dateabase :)
Collection exists
Collection has error, collection not found
I don't understand why the test for a collection seems ok, but when I try
to get the collection there is an error.
--
You received this message because you are subscribed to the Google Groups "ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arangodb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arangodb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.