mongodb - Problems adding data using onCreateUser() in Meteor -
i trying hook oncreateuser function accounts-password package add information collection when account created. have added piece of code server.js
//server.js var shopdetails = { name = "", postcode = "", type = ""; opentime = "", closetime = "", phonenum = 0, dashboarddetails = false //until shop populates these fields createdby = user._id //_id taken function below } accounts.oncreateuser(function(options,user){ var userid = user._id; shoplist.insert(shopdetails); return user; });
the 2 collections have in app -
- shoplist = new mongo.collection("shoplist") //held in collections folder
- user collection comes bundled accounts-password
once new user has created account, wanted insert object required fields (shopdetails) shoplist collection (for purpose of creating personal dashboard each shop @ later point) . after creating few test accounts, cannot see them in shoplist collection in robomongo, know user accounts being inserted can see them in user collection. can tell me going wrong?
what if print
console.log(shopdetails)
inside hook?
also try use callbacks on insert second parameter, can this
shoplist.insert(shopdetails,function(error,result){ if(error){ console.log(error); //should print error , more =d }else{ console.log(result); } });
also why don better like
insertshopdetails = function(userid){ var shopdetails = { name = "", postcode = "", type = ""; opentime = "", closetime = "", phonenum = 0, dashboarddetails = false, createdby = userid } shoplist.insert(shopdetails,function(error,result){ if(error){ console.log(error); }else{ console.log(result); } }); }
and call inside oncreatedhook
accounts.oncreateuser(function(options,user){ var userid = user._id; insertshopdetails(userid); return user; });
the above thing should work, why dont better using hook?
meteor add matb33:collection-hooks meteor.users.after.insert(function(userid, doc, modifier) { var shopdetails = { name = "", postcode = "", type = ""; opentime = "", closetime = "", phonenum = 0, dashboarddetails = false createdby = userid } shoplist.insert(shopdetails); });
Comments
Post a Comment