在mongo ruby驱动程序的Rails应用程序(5.2)中使用mongo(3.4)。我需要在集合上使用排序规则以允许不区分大小写的文本搜索,为此,我收到警告,我需要将setFeatureCompatibilityVersion添加到3.4。
client = Mongo::Client.new(['127.0.0.1:27017'], :database => 'leads')
db = client.database
db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
collection_name = "#{user.id.to_s}"
@collection = client[collection_name.to_sym, { "collation" => { "locale" => "en_US" } }]
...
但是获得NoMethodError (undefined method
adminCommand'为#)`
我在这种情况下不使用蒙古包,因此无法使用模型来使用蒙古包。
我该如何解决?
UPDATE ::
刚刚起作用的是我用mongo访问mongo shell并输入了
db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
{ "ok" : 1 }
此命令仅应直接在shell中应用于数据库吗?
Ruby驱动程序中运行任意命令的方法是Database#command
:
https://api.mongodb.com/ruby/current/Mongo/Database.html#command-instance_method