Harshit Laddha
Harshit Laddha

Reputation: 2124

Javascript Objects properties not getting added

I have a couple of commands in my server side mongoose code, but i don't know why I am not able to add more properties to this data object on the server side, whereas I am able to do the same in the chrome console without any problems

var data = {};
        data = noteData;
        data.uploader = req.user.username;
        console.log(data.uploader);
        console.log(req.user.username);
        data.actualFileName = actualFileName;
        console.log(data.actualFileName);
        console.log(actualFileName);
        data.storedFileName = storedFileName;
        console.log(data.storedFileName);
        console.log(req.storedFileName);
        console.log(data);

the noteData has the following values -

{"title":"1","subject":"2","author":"3","department":"CSE","college":"MSRIT","description":"45","details":"5","tags":["6"]}

and the console output for the above code fragment is -

undefined
[email protected]
undefined
[ 'EIPR.odt', 'EIPR.docx' ]
undefined
undefined
{"title":"1","subject":"2","author":"3","department":"CSE","college":"MSRIT","description":"45","details":"5","tags":["6"]}

What else should i try to debug this error or what other information should i provide?

Upvotes: 0

Views: 54

Answers (2)

Harpreet Singh
Harpreet Singh

Reputation: 2671

Try this method, if it doesn't work, show us your mongoose code.

var data = {};
data = noteData;

data['uploader'] = 'USER_NAME';
console.log(data.uploader);
data['actualFileName'] = 'FILE_NAME';
console.log(data.actualFileName);
data['toredFileName'] = 'STORE_FILENAME';
console.log(data.storedFileName);
console.log(data);

Object {title: "1", subject: "2", author: "3", department: "CSE", college: "MSRIT"…}
actualFileName: "FILE_NAME"
author: "3"
college: "MSRIT"
department: "CSE"
description: "45"
details: "5"
subject: "2"
tags: Array[1]
title: "1"
toredFileName: "STORE_FILENAME"
uploader: "USER_NAME"
__proto__: Object

Upvotes: 1

Tyler
Tyler

Reputation: 183

when you say data = noteData - it is now the same type as noteData... so if noteData.property does not exist, data's property will not exist.

Upvotes: 1

Related Questions