2 部分问题。
1是mongodb查询本身,接下来是在mgo中怎么做。
如何查询 1 个类别类型的文档(结果应该是类别类型),其中slug: "general"?
我选择这种布局的原因是因为我读到 mongodb 的优势是嵌入“结构”的性能但是我担心我必须让“类别”和“论坛”成为自己的集合并重写大量代码,我想避免这是因为客户端的每个视图无论如何都需要访问这些模型,这将导致每个新页面加载(对于类别和论坛)的 1-2 个额外查询,并且使用 mongodb 的优势将消失。
接下来的问题是,我将如何更新或删除一个特定的嵌入文档?
有没有办法直接从 mongodb 获取类别文档,而无需分离文档或在 Go 中编写 find、update、delete 函数,以及如何?
这种结构:
{
"_id" : ObjectId("5303d1a2d6194c0f27000001"),
"name" : "darko",
"description" : "darko",
"subdomain" : "darko",
"domain" : "mango.dev",
"created" : ISODate("2014-02-18T21:33:22.115Z"),
"category" : "Brains",
"owner" : "52b1d74dd6194c0646000002",
"members" : [
"52b1d74dd6194c0646000002"
],
"categories" : [
{
"_id" : ObjectId("5303d1a2d6194c0f27000003"),
"name" : "Admin and Moderator Area",
"slug" : "admin-and-moderator-area",
"adminonly" : true,
"membersonly" : false,
"forums" : [
{
"_id" : ObjectId("5303d1a2d6194c0f27000005"),
"name" : "Admin Discussion",
"slug" : "admin-discussion",
"text" : "This is the main forum for administrative topics."
}
]
},
{
"_id" : ObjectId("5303d1a2d6194c0f27000002"),
"name" : "General",
"slug" : "general",
"adminonly" : false,
"membersonly" : false,
"forums" : [
{
"_id" : ObjectId("5303d1a2d6194c0f27000004"),
"name" : "General Discussion",
"slug" : "general-discussion",
"text" : "Talk about everything and anything here in this general discussion forum"
}
]
}
]
}
拉莫斯之舞
相关分类