Stefan Schuchlenz
Stefan Schuchlenz

Reputation: 117

Extract data from mongoid into Rails fixtures

Is there a way to save data from my local development environment (running Rails 3 and mongoid) into fixtures or a dump file for later reimport into my production environment? As far as I have seen rake db:dump does not work with mongoid.

update: to further clarify what I am trying to do: sometimes it would be nice to add live data (which will be used in the production site too) directly when developing a project to work with real data instead of seeded samples. It would be nice to have a feature (e.g. rake task) to dump this data into a file and then re-import it with rake on the production server.

Upvotes: 0

Views: 585

Answers (1)

xlembouras
xlembouras

Reputation: 8295

You can have some data on your db/seeds.rb file and use rake db:seed command to import them. See documentation

db/seeds.rb is mainly used for some basic data, not a whole database. If you want to migrate a full db you should do it manually with mongodump and mongoimport commands.

UPDATE

Having production data to your development environment can be tricky.

If your data are not that big you can set up a periodic operation to put a snapshot of production to your development db.

If your db is big (eg some hundreds of MBytes or even GB) you will not be able to have everything in development easily and frequently updated. In that case I think you will need to decide which data are needed and fetch some of them by different criteria each time.

eg fetch collection x or fetch 1000 records from collection x

Of course all these are too general for an answer. You need to examine exactly what is the minimum set that fits your needs and try to satisfy that.

Upvotes: 1

Related Questions