36 lines
1001 B
Ruby
36 lines
1001 B
Ruby
# encoding: utf-8
|
|
|
|
require 'mongo'
|
|
include Mongo
|
|
|
|
DB_BASE_NAME = "production"
|
|
|
|
main_db = MongoClient.new("localhost", 27017).db("#{DB_BASE_NAME}_#{0}")
|
|
main_bulletin = main_db["bulletins"]
|
|
main_cat = main_db["bulletin_categories"]
|
|
|
|
copy_db = MongoClient.new("localhost", 27017).db("#{DB_BASE_NAME}_#{11}")
|
|
copy_bulletin = copy_db["bulletins"]
|
|
copy_cat = copy_db["bulletin_categories"]
|
|
|
|
|
|
main_cat.find(key: /rss_/).each do |category|
|
|
category_id = \
|
|
if cat = copy_cat.find_one(key: category['key'])
|
|
cat['_id']
|
|
else
|
|
copy_category = category.clone
|
|
copy_category['_id'] = BSON::ObjectId.new
|
|
copy_cat.save copy_category
|
|
end
|
|
|
|
main_bulletin.find(bulletin_category_id: category['_id']).each do |bulletin|
|
|
unless copy_bulletin.find_one(rss_link: bulletin['rss_link'])
|
|
copybulletin = bulletin.clone
|
|
copybulletin['_id'] = BSON::ObjectId.new
|
|
copybulletin['bulletin_category_id'] = category_id
|
|
bulletin_id = copy_bulletin.save copybulletin
|
|
end
|
|
end
|
|
end
|