Let me start with my use case. I have two different instance of mongoid database hosted per region based with similar model. And depending on user input, the code gets the results from respective mongo instance in my rails app. I am not sure what is the best way of doing this however I used Model.with approach and configured two clients in mongoid.yml.
With mongoid <5.0, this worked perfect. However, recently I am upgrading to mongoid 6.2 with which Model.with now accepts block and my query is not producing any results.
Heres example code.
I changed my code from below (mongoid <5 which worked fine)
results = SomeModel.with(client: "region1").where(name: 'John')
to (mongoid >= 6.2)
results = SomeModel.with(client: "region1") do |mymodel|
mymodel.where(name: 'John')
end
With new code the results are empty. Not sure if I am doing anything wrong. However, below code works fine if want just one record:
results = SomeModel.with(client: "region1") do |mymodel|
mymodel.where(name: 'John').first
end
I would really appreciate if there is any other idea for my use case.