형식 오류가 : newUser.save가 확산 연산자의 속성을 할당하기 전에합니다 (createNew 함수) 함수속성을 할당 한 후 저장 기능이 아닌 이유는 무엇입니까?
아닌 상기 userModel 객체 (몽구스 의해 설계와 같은)의 기능을 할당하지만 후, 저장 기능을 갖는 더 이상 액세스 할 수 없습니다. 누군가 이것이 이것이 왜이고 어떻게 돌아 다니는지 설명 할 수 있습니까?
const mongoose = require('mongoose')
const UserSchema = new mongoose.Schema({
facebookid: String,
firstname: String,
lastname: String,
email: String,
timezone: Number,
gender: String,
invitationid: String,
referralid: String,
locale: String,
stage: String
})
const User = mongoose.model('User', UserSchema)
const createUser =() => new User()
module.exports = {
createNew : userInfo => {
const userModel = createUser()
const newUser = { ...userModel,
facebookid: userInfo.fid,
firstname: userInfo.first_name,
lastname: userInfo.last_name,
locale: userInfo.locale,
timezone: userInfo.timezone,
gender: userInfo.gender,
invitationid: userInfo.invitationid,
referralid: userInfo.referralid,
stage: 'NA'
}
return newUser.save()
}
}
감사합니다. 메이트
나는 생성자의 매개 변수에 대해 몰랐다. 우아한 솔루션과 완벽하게 작동, 정말 고마워! – matetukacs