Reputation: 597
I am planning and researching my switch from MySQL to MongoDB right now and I just had an interesting thought... I have a bunch of hierarchical objects that I need to store in the database. My current method is to have a bunch of embedded documents in a collection. They will never need to be searched for. Would it possibly make sense just to serialize the PHP objects, stick them in the DB, and then unserialize them back into PHP objects when I want to use them? The alternative is using Doctrine as my ORM.
My programming intuition tells me that this is bad design and is limiting, but I feel like serializing and unserializing would be very fast and eliminate the need for an ORM.
What's your opinion? Good design or bad design?
Upvotes: 4
Views: 2160
Reputation: 625
Serializing objects is VERY useful when you have to cache things, such as RSS feeds.
I find it good use to serialize it, but I would also make sure that that can never be editing as a string without unserializing it first!
Upvotes: 0
Reputation: 3605
In many cases this would be considered bad design, but it could work if all of the following apply:
SELECT
+ deserialize()
will be slower than just SELECT
)Upvotes: 11
Reputation: 10429
It kind of depends entirely on what you intend to do.
If it's always the same object each request deals with or there are no relationships between each request, it might be ok.
But to me there are a lot of downsides:
Upvotes: 1