-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
I have noticed inconsistent behaviour when using the
(collection: collection_name)
modifier to force mongoid to read from / write to a different collection.
First of all this doesn't work as expected:
Search.with(collection: "search_collection_1").where(...)
doesn't work. Instead you need to add
to make it work, like:
ruby
Search.all.with(collection: "search_collection_1").where(...)
Furthermore, when I create a new object with
with
then consequent updates to the object use the correct collection, i.e:
ruby
search = Search.with(collection: "search_collection_1").create(id: "xyz", data1: "some useful data...")
search.inc(usage: 1) # this will update the document in the correct collection
However during retrieval this is not the case:
ruby
search = Search.with(collection: "search_collection_1").where(id: "xyz").first
search.inc(usage: 1) # this will update the document in the default "searches" collection (practically it will do nothing, since the document is not there)
search.with(collection: "search_collection_1")
search.inc(usage: 2) # now it use the proper collection
`
Is this something that will be fixed?
Or is it supposed to work like this?