ismael.
ismael.

Reputation: 438

Collections not being read correctly after mongomapper is replaced by mongoid and mongo driver is updated

MongoDB V3.2

Upgraded the following the gems:

Ruby Mongo Driver from 1.11.1 to 2.10.4 + dependencies Replaced MongoMapper 0.13.1 with Mongoid 5.4.1 + dependencies

After these changes, I noticed immediately that any collections that were placed in an additional module (FolderModuleName::ClassName) that could display data in MongoMapper would no longer display any data.

The only collections that would display data would be those without any modules for example a class that looked like this class DataClass.

Upvotes: 0

Views: 48

Answers (1)

ismael.
ismael.

Reputation: 438

I was able to figure out the issue by using the rails console and connecting to my database using the ruby mongo driver. (https://docs.mongodb.com/ruby-driver/master/quick-start/)

client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'dbname')
db = client.database

db.collections # returns a list of collection objects
db.collection_names # returns a list of collection names

Using db.collection_names in the rails console I was able to see that any collection with a module was saved like this:

module_name.collection_name

After my upgrade the only collections names with modules I could read were:

module_name_collection_name

With this information, I added the following code to the ruby models affected:

store_in collection: 'module_name.collection_name'

This fixed my issue.

The reason collections without modules could be read without using the code above is because the collection names were simply stored as:

collection_name

Adding 'store in' in that case would just be redundant.

Upvotes: 1

Related Questions