Discussion:
[arangodb-google] Noob Problem: collection not found error using ArangoDB for Go
Jason J
2018-06-14 03:20:43 UTC
Permalink
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.
--
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.
Jason J
2018-06-14 14:02:51 UTC
Permalink
Ok, I think I found part of the problem. But let me add some extra context.
I manually added a "character" collection to the arangodb using the arango
web service for the db. So I know the collection exists. This morning(my
morning) I changed the output log for checking if the connection to exist.
I read that the return value is bool, so I used the the fmt to log the
found result. The return was false. So this was my misunderstanding. I went
over the web interface again and eventually recalled that the web interface
requires selecting what database to look at. Something I forgot since my
last foray into ArangoDb with node js last year. I changed my db setting to
my test one and saw all the collection I made last year. Once I created the
collection in the right database the system went forward working. The
collection now exists properly and no errors are thrown.

Total noob problem.
Post by Jason J
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.
--
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.
Loading...