[开始构建一个显示城市中多个地方的网络应用。但是在此之前,请尝试在CouchDB中建立良好的数据库建模基础。
因此,每个city是一个文档,并且在城镇中具有不同的places。 电子邮件是发送/添加地点的人。 comments用于在此处获取其他信息。尝试按层次工作。
下一步是显示传单地图上的所有位置,并按“城市”进行过滤。
- city
- place 1
- place 2
- ...
- place x
这里是我的文档模型:
{
"_id": "52888cacec450d22e4baa0c1754cb777",
"_rev": "2-c916a9d3ce0a86a775dd232996c0f865",
"zip": "8660",
"city": "Adinkerke",
"province": "West-Vlaanderen",
"lng": 2.5896028375712,
"lat": 51.06926315,
"comments": "",
"locations": [
{
"places": "1",
"lat": "51.074319",
"lng": "2.599509",
"street": "Kerkweg",
"comments": "",
"email": "c***@gmail.com",
"published": "27/12/2019"
},
{
"places": "1",
"lat": "51.075027",
"lng": " 2.602127",
"street": "Dorpstraat",
"comments": "Parking Dorpstraat/Kerkweg",
"email": "c***@gmail.com",
"published": "27/12/2019"
}
]
}
一些建议,是否可以更好?
而是将模型从内到外翻转-让每个位置成为一个单独的文档,其中包含“城市”字段,然后使用键入“城市”的地图来获取城市中的所有位置。这样,您就可以减少更新冲突和随着应用程序扩展而不断增长的文档的风险。
function(doc) {
if (doc && doc.city) {
emit(doc.city, null);
}
}
[一般建议是:小型文档,不可变模型。参见https://blog.cloudant.com/2019/11/21/Best-and-Worst-Practices.html