我正在尝试创建一些树形结构.
我想访问我的数据如下:
data[key1][key2]
Run Code Online (Sandbox Code Playgroud)
但是,key1和key2具有对称关系; 以下是永远的:
data[key1][key2] == data[key2][key1]
Run Code Online (Sandbox Code Playgroud)
更具体地说,我有data[key1][key2]并data[key2][key1]指向同一个对象,因此对一个对象的更改会影响另一个对象.
我的问题出现了,因为我希望删除底层对象.我知道我是否使用:
delete data[key1][key2];
Run Code Online (Sandbox Code Playgroud)
data[key2][key1] 仍然指的是对象.
我的问题是:有没有办法删除底层对象,或用虚假的东西覆盖它,这样上面的两个属性都会评估为falsey?
我正在尝试使用用户定义的键创建文档,如下所示:
package main
import (
"fmt"
driver "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/http"
)
type doc struct {
_key string `json:"_key"`
}
func main() {
conn, _ := http.NewConnection(http.ConnectionConfig{
Endpoints: []string{"http://localhost:8529"},
})
c, _ := driver.NewClient(driver.ClientConfig{
Connection: conn,
Authentication: driver.BasicAuthentication("root", "test"),
})
db, _ := c.CreateDatabase(nil, "dbname", nil)
// delete the collection if it exists; then create it
options := &driver.CreateCollectionOptions{
KeyOptions: &driver.CollectionKeyOptions{
AllowUserKeys: true,
},
}
coll, _ := db.CreateCollection(nil, "collname", options)
meta, _ := coll.CreateDocument(nil, doc{ _key: "mykey" })
fmt.Printf("Created document with …Run Code Online (Sandbox Code Playgroud)