I am quite new in JS, mongoDB and mongoose.
I would like to try to copy some documents field to another document. After that i would like to delete the original document.
Here is my mongoDB collection:
[
// twitter account
{ "_id" : "585bbba59659501d68f997ec",
"logIn" : "twitter" ,
"pollIds" : { "local" : [ ] , "facebook" : [ ] , "twitter" : [ ]} ,
"twitter" : { "username" : "xxxxx" ,
"displayName" : "xxxx yyyyy" ,
"token" : "" , //place for copied twitter token
"id" : "99999999999999999"} ,
"__v" : 0},
//facebook account connected with twitter and local
{ "_id" : "585bbba99659501d68f997ed",
"logIn" : "facebook" ,
"pollIds" : { "local" : [ ] , "facebook" : [ ] , "twitter" : [ ]} ,
"twitter" : { "username" : "xxxxx" ,
"displayName" : "xxxx yyyyy" ,
"token" : "tokentokentokentoken" , //token what i want to copy
"id" : "99999999999999999" ,
"dbId" : "585bbba59659501d68f997ec"} ,
"facebook": { "email" : "xx@xx.com" ,
"displayName" : "xxx yyy" ,
"token" : "facebooktoken" ,
"id" : "8888888888888888"} ,
"local" : { "password" : "local user password" ,
"email" : "ggg@ggg.com" , //email what i want to copy
"dbId" : "585bbbc29659501d68f997ee"},
"__v" : 0}
//local account
{ "_id" : "585bbbc29659501d68f997ee",
"logIn" : "local" ,
"pollIds" : { "local" : [ ] , "facebook" : [ ] , "twitter" : [ ]} ,
"local" : { "password" : "local password" ,
"email" : ""} , place for copied local email
"__v" : 0}
]
What I try to achieve is disconnect TWITTER and LOCAL accounts from FACEBOOK account. Here is how I try to do this :
- from FACEBOOK account copy TWITTER token to the TWITTER account
- from FACEBOOK account copy LOCAL email to the LOCAL account
from FACEBOOK account remove TWITTER and LOCAL account assigning them undefined
// local = undefined // // twitter = undefined //
My problem is: after that I remove LOCAL and TWITTER accounts, the copied fields disappears as well. I think I just copied its reference and not its value. If that is the situation how i can make this work ?
I hope my question doesn't seem messy. This is my first post here. Thank for your answer.