2017-02-07 8 views
0

これは私のモデルです。ここで私は応答と呼ばれるサーバーからオブジェクトを受信して​​います。今私はこの応答オブジェクトでデータベースを更新する必要があります。 しかし、私は変数だけを更新できますが、父のようなオブジェクトは更新できません。 父は1つのオブジェクトで、父のファーストネームを更新する必要があります。しかし、私がFather.Firstnameを使用して予期しないトークンを使用すると、エラーが発生します。あなたは、キーオブジェクト名を、あなたが文字列で行うように、それはdouble("")またはsingle('')引用符をwithing囲む必要でdot(.)文字を使用する必要がある場合 ..この問題を克服する方法をは、mongooseを使用してオブジェクト内の値を更新する必要があります

var User = mongoose.model('User', userSchema); 

function createStudent(response) { 
    console.log(response); 
    var list = new User({ 
     Firstname : response.Fname, 
     Age : response.age, 
     Lastname : response.Lname, 
     Father.Firstname : response.fatherfname, 
     Father.Lastname : response.fatherlname, 
     Father.Occupation : response.occupation, 
     Father.PlaceOfWork : response.placeofwork, 
     Father.OfficialAddress : response.officaladd, 
     Father.EmailId : response.emailid, 
     Father.PhoneNo : response.phoneno, 
     Father.MobileNo : response.mobileno, 


    }); 
    list.save(); 
    } 

答えて

1

私を助けてください。

だからあなたのコードは次のように書く -

"Father.Firstname" : response.fatherfname, 

代わりの

Father.Firstname : response.fatherfname, 
+1

ええ、私はそれが最初では動作しませんと思ったが。どうもありがとうございます –

関連する問題