有一个关于Casbah的教程:
http://api.mongodb.org/scala/casbah/current/tutorial.html
但是我发现很难按照教程学习,因为我还在学习 Scala。
我只想了解如何使用 Casbah 进行简单的 CRUD 操作,然后才能更高级。
给出以下领域模型:
class Hotel (var name: String, var stars: Int, val address: Address)
class Address(var street:String, var city: String, var postCode: String)
val address = new Address(street = "1234 st", city = "edmond", postCode = "1232234", country = "USA" )
val hotel = new Hotel(name = "Super Nice", stars = 4, address = address)
val address2 = new Address(street = "main st", city = "edmond", postCode = "1232234", country = "USA" )
val hotel2 = new Hotel(name = "Big Hotel", stars = 4, address = address2)
上面给出了什么 Casbah 代码来完成这些任务?
(1)在mongodb中保存两个酒店
(2)找到所有星级等于或大于4的酒店。这应该给我一个我可以迭代的列表
(3)找到一家名为“Super Nice”的酒店,改名为“Ultra Nice”
(4) 获取所有酒店的地址并将国家更改为小写并保存在数据库中