gpt4 book ai didi

ruby-on-rails - 从 mongoid 数据库中删除属性

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:57 25 4
gpt4 key购买 nike

我在 mongoid 中有一个模型用户,其属性为:country。我想从模型和任何现有用户文档中删除该字段。我怎样才能做到这一点?

# user.rb
class User
include Mongoid::Document

field :name, type: String
#field :country, type: String --> field removed from model

end

最佳答案

对于数据库中的所有用户:

User.all.each { |user| user.unset(:country) }

或者对于单个用户:

User.unset(:country)

关于ruby-on-rails - 从 mongoid 数据库中删除属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20542282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com