Fix insert for older mongodb.

This commit is contained in:
BoHung Chiu 2022-11-16 22:00:38 +08:00
parent 1b48d72591
commit 497c32685a
1 changed files with 10 additions and 3 deletions

View File

@ -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|^ */,"")