我正在使用passport-bnet
來驗證使用battlenet的用戶(他們可以有多個服務)。我有如下的格式用戶對象:根據JSON中的值插入表格
{
"id": 1,
"name": "Meow",
"battlenet": {
"id": 5,
"tag": "obviously-not-a-real-battletag#1234"
}
}
當我驗證用戶,我給出的響應交戰用戶的ID。我試圖做的是從這個JSON字段中選擇ID並創建它,如果它不存在。
passport.use(new Battlenet({/**...*/}, function (accessToken, refreshToken, profile, done) {
database
.select('*')
.where('battlenet->id', '=', profile.id)
.then(user => done(null, user))
.catch(done);
});
但是,我有點麻煩。如何插入此用戶文檔以包含一些默認值?從本質上講,我想在蒙戈
{
$setOnInsert: { name: profile.tag.replace(/\W/, '') },
$set: { battlenet: profile }
}
這將如何通過knex和Postgres做類似這種修改的東西嗎?