To query my MongoDB database I call:
MyClass.collection.find({ foo: "bar" })
If I want to constantize MyClass
from a string I call:
"MyClass".safe_constantize.collection.find({ foo: "bar" })
This will return an array that I can work with. The array contains hash-like objects of the class BSON::Document
.
But what if I want to query for a class that exists in the db, but not in my Rails app?
If I call "UnknownClass".safe_constantize
it returns nil
.
If I could move past that point I would have an array of regular key/value pairs to work with, and it wouldn't be a problem that the original class that was stored inside the db was unknown to my Rails app.
So how do I query for a class that my Rails app don't know about?