How do I serialize/de-serialize data with embedded documents?

154 views
Skip to first unread message

dblock

unread,
Feb 13, 2011, 9:58:43 AM2/13/11
to Mongoid
I'm trying to write an export/import for data with Rake, currently
using to_json and from_json.

I see two problems when doing this:

object = model.new.from_json line
object.save!

1) If the object already exists in the database, MongoID tries to
insert a dup. How do I update this data?
2) I am missing embedded documents. Is there a way to serialize the
entire thing?

Thx
-dB.

dblock

unread,
Feb 13, 2011, 2:41:14 PM2/13/11
to Mongoid
Please ignore 2), my mistake.

Durran Jordan

unread,
Feb 14, 2011, 10:26:24 AM2/14/11
to mon...@googlegroups.com
Try:

object = Model.instantiate(json_as_a_hash)
object.save!

2011/2/13 dblock <dblock...@gmail.com>
Reply all
Reply to author
Forward
0 new messages