英文:
How to insert a reference type field on Firestore with Golang
问题
在我的数据库中,我在一些文档中使用了引用类型的字段,就像这样:
我试图将这些属性插入到Firestore中:
_, err = userReference.Set(context.Background(), models.User{
Jobs: []*firestore.DocumentRef{employeeReference},
})
在这种情况下,我使用了一个*DocumentRef
的数组,但即使是一个唯一的DocumentRef
也不起作用,我还尝试将其插入为DocumentRef
类型而不是指针,也不起作用,我的User
类型是这样的:
type User struct {
Jobs []*firestore.DocumentRef `json:"jobs"`
}
有什么办法可以从Go中插入这种类型的数据吗?在JavaScript SDK中,我记得只能直接将DocumentReference
类型插入到已实现的对象中,但我在使用Golang时遇到了这个问题。
英文:
Inside my database i'm using fields of reference type on some documents, like this:
I'm trying to insert these property on firestore
_, err = userReference.Set(context.Background(), models.User{
Jobs: []*firestore.DocumentRef{employeeReference},
})
On this case I used an array of *DocumentRef
, but even if is a unique DocumentRef
doesn't work, I also tried to insert as type DocumentRef
instead of the pointer, and also doesn't work, my User
type is like that:
type User struct {
Jobs []*firestore.DocumentRef `json:"jobs"`
}
There's something that I can do to insert this type of data from go? On Javascript SDK, I remember that is only to insert the DocumentReference
type directly on object that is achieved, but I'm facing this problem with Golang.
答案1
得分: 1
我对Golang没有经验,但是你可以在这里找到许多示例。
我想知道下面的代码是否能给你一些提示:
_, err := userReference.Set(context.Background(), models.User{
Jobs: []*firestore.DocumentRef{client.Doc("/selfManagedEmployees/K4qhd5k1c...")}
})
英文:
I have no experience with Golang but here you can find many examples.
I wonder if something like the following can give you any hints:
_, err := userReference.Set(context.Background(), models.User{
Jobs: []*firestore.DocumentRef{client.Doc("/selfManagedEmployees/K4qhd5k1c...")}
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论