编辑 MongoMapper 文档
在 MongoMapper 文档中我找不到任何实际编辑文档的方法。我在其他地方也找不到任何东西。我能找到的唯一方法是这种方法:
class User
include MongoMapper::Document
key :name, String
end
user = User.create( :name => "Hello" )
user.name = "Hello?"
puts user.name # => Hello?
有更简单的方法吗?我知道在 DataMapper 中,我可以一次编辑多个键(或属性,在 DM 的情况下),但使用 MM 时,我一次只能编辑一个。
我错过了什么吗?
Nowhere in the MongoMapper documentation can I find any methods for actually editing documents. I can't find anything elsewhere, either. The only way I could find, is this method:
class User
include MongoMapper::Document
key :name, String
end
user = User.create( :name => "Hello" )
user.name = "Hello?"
puts user.name # => Hello?
Is there an easier way to do this? I know that in DataMapper, I can edit multiple keys (or properties, in DM's case) at once, but with MM, I can only do one at a time.
Am I missing something, or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像编辑 ActiveRecord 对象一样编辑文档/对象:为属性分配一些值,然后调用
save
。您的示例只有一个键,因此这是一个具有多个键的键:
然后:
然后:
或者有
update_attributes
:也许我不确定您在问什么。
You edit your documents/objects the same way you'd edit an ActiveRecord object: assign some values to attributes and then call
save
.Your example only has one key so here's one with multiple keys:
And then:
And later:
Or there's
update_attributes
:Maybe I'm not sure what you're asking.