diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index dd94ca6..8c1833b 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -606,11 +606,16 @@ class Admin::SitePanelController < OrbitAdminController user_data._id = user._id; db.users.update(user_query, {$set: user_data}); }else{ - db.users.insertOne(user_data); + var bulk = db.users.initializeUnorderedBulkOp(); + bulk.insert(user_data); + bulk.execute(); } user_query = {user_name: \"#{user_attrs['user_name']}\"}; user = db.users.findOne(user_query); var member_query = {_id: user.member_profile_id}; + if (member_query[\"_id\"] == null){ + member_query[\"_id\"] = null; + } var member = user.member_profile_id ? db.member_profiles.findOne(member_query) : null; var member_data = #{member_attrs.to_json}; member_data.created_at = time; @@ -619,8 +624,10 @@ class Admin::SitePanelController < OrbitAdminController delete member_data[\"uid\"]; member = db.member_profiles.update(member_query, {$set: member_data}); }else{ - member = db.member_profiles.insertOne(member_data); - user_data.member_profile_id = member.insertedId; + var bulk = db.member_profiles.initializeUnorderedBulkOp(); + bulk.find(member_query).upsert().updateOne(member_data); + var result = bulk.execute(); + user_data.member_profile_id = result.getUpsertedIds()[0][\"_id\"]; db.users.update(user_query, {$set: user_data}); } }()' {{db_name}}""".gsub(/\n|^ */,"")