더북(TheBook)

Template.addressInput.events의 전체 코드는 다음과 같다.

~/Projects/addressBook/client/addressList.js

생략
Template.addressInput.events({
    ‘click button[name=saveAddress]’ (evt,tmpl){

    <span class="cm">/* input 박스 값으로 입력 데이터 만들기 */</span>
    <span class="kd">var</span> <span class="nx">address</span> <span class="o">=</span> <span class="p">{</span>
        <span class="nx">name</span>    <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=name]"</span><span class="p">).</span><span class="nx">value</span>
        <span class="p">,</span><span class="nx">phone</span><span class="p">;</span>   <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=phone]"</span><span class="p">).</span><span class="nx">value</span>
        <span class="p">,</span><span class="nx">email</span><span class="p">;</span>   <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=email]"</span><span class="p">).</span><span class="nx">value</span>
        <span class="p">,</span><span class="nx">company</span> <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=company]"</span><span class="p">).</span><span class="nx">value</span>
        <span class="p">,</span><span class="nx">birthday</span>    <span class="o">:</span> <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=birthday]"</span><span class="p">).</span><span class="nx">value</span>
    <span class="p">};</span>
    <span class="cm">/* Insert하기 */</span>
    <span class="nx">AddressBook</span><span class="p">.</span><span class="nx">insert</span><span class="p">(</span><span class="nx">address</span><span class="p">);</span>
    <span class="cm">/* input 값 초기화하기 */</span>
    <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=name]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
    <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=phone]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
    <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=email]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
    <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=company]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
    <span class="nx">tmpl</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">"input[name=birthday]"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="p">}</span>

});

노트 프로젝트 폴더에서 meteor mongo라는 명령을 이용하면 미티어가 실행시킨 몽고DB 셸을 접속할 수 있다(단, meteor run으로 미티어는 실행 중이어야 한다). 셸에서는 몽고DB native 명령을 모두 쓸 수 있다. 혹시, addressBook 컬렉션에 입력한 픽스처 데이터나 애플리케이션에서 입력된 데이터를 삭제하고 싶다면 몽고DB 네이티브 메서드인 remove를 이용하여 데이터를 삭제할 수 있다.

 

몽고DB 컬렉션 초기화

~/Projects/addressBook$ meteor mongo

MongoDB shell version: 3.3.6

connecting to: 127.0.0.1:3001/meteor

meteor:PRIMARY> db.addressBook.remove({});


단, 운영 중인 데이터베이스에 위와 같은 명령을 실행하면 안 된다.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.