Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ****** Schema ******
- var Account = new Schema({
- username: {type: String, unique:true},
- password: String,
- profile: {
- name: String,
- email: String,
- phone: [{type: String, number: Number }],
- address: [{type: String, address: String }]
- },
- });
- // ****** find and update ******
- Account.findOne({ username: req.username }, function ( err, account ) {
- if ( err )
- res.json ({success: false, err: err });
- else {
- if ( req.body.name ) account.profile.name = req.body.name;
- if ( req.body.email ) account.profile.email = req.body.email;
- if ( req.body.phone ) {
- console.log (( JSON.parse ( req.body.phone ) ));
- account.profile.phone = JSON.parse ( req.body.phone ); //THIS THROWS ERROR
- }
- account.save ( function ( err, account ){
- if ( err ) res.json ({success: false, err: err });
- res.json ({ success: true, account: account });
- });
- }
- });
- // ERROR RETURNED TO POSTMAN
- {
- "success": false,
- "err": {
- "message": "accounts validation failed",
- "name": "ValidationError",
- "errors": {
- "profile.phone": {
- "message": "Cast to Array failed for value \"[object Object]\" at path \"profile.phone\"",
- "name": "CastError",
- "kind": "Array",
- "value": [
- {
- "device": "Mobile",
- "number": "9790846755"
- }
- ],
- "path": "profile.phone"
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment