javascript - Not insert but upsert if document is not found -


what need check if company did not add name insert company name else update company name. in project, user after registration can complete profile completly. when user fills "company name" input , clicks save button, company name should added list of companies, if user changes name of company, should changed list of companies. here code user form html:

 <template name="userformedit">   <form class="form new-company">     <div class="form-group">     <label for="companyname">comapany name</label>     <input type="text" class="form-control" name="companyname" id="companyname"     placeholder="" value="{{companyname}}">     </div>   </form </template>   <div class="container-fluid text-center bg-grey">         <h2>portfolio</h2>         <h4>what have created</h4>         <div class="row text-center">             {{ #each companyprofile }}             {{> companyview }}             {{/each }}         </div>     </div> </template> <template name="companyview">     <div class="col-sm-4">         <div class="thumbnail">             <img src="..." alt="paris">             <p><strong>{{companyname}}</strong></p>             <p>yes, built paris</p>         </div>     </div> </template> 

and .js file:

currentuserprofile = new meteor.collection('userprofile'); //in client template.userformedit.events({         'submit .new-company' : function(event){             var companynamevar = event.target.companyname.value;             currentuserprofile.update(this._id,{$set: {companyname: companynamevar}});         }     });  template.homepage.helpers({         companyprofile: function(){             return currentuserprofile.find();         }     }); 

meteor has built in upsert collections. can use that.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -