더북(TheBook)

~/Projects/addressBook/lib/collection.js

AddressBook = new Mongo.Collection(“addressBook”);

~/Projects/addressBook/server/fixture.js

var fixtures = [
    {
        “name”: “Acton Byers”,
        “phone”: “010-5533-9991”,
        “email”: “faucibus.orci.luctus@interdum.ca”,
        “company”: “Neque Incorporated”,
        “birthday”: “1994/06/30”
    },

생략

<span class="p">{</span>
    <span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Yardley Herrera"</span><span class="p">,</span>
    <span class="s2">"phone"</span><span class="o">:</span> <span class="s2">"010-6744-4901"</span><span class="p">,</span>
    <span class="s2">"email"</span><span class="o">:</span> <span class="s2">"elit@Donecnibhenim.org"</span><span class="p">,</span>
    <span class="s2">"company"</span><span class="o">:</span> <span class="s2">"Vulputate Eu Associates"</span><span class="p">,</span>
    <span class="s2">"birthday"</span><span class="o">:</span> <span class="s2">"1987/07/17"</span>
<span class="p">}</span>

];

Meteor.startup(function () {

<span class="k">if</span><span class="p">(</span><span class="nx">AddressBook</span><span class="p">.</span><span class="nx">find</span><span class="p">().</span><span class="nx">count</span><span class="p">()</span> <span class="o">===</span> <span class="mi">0</span><span class="p">){</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"데이터가 존재하지 않습니다. fixture 데이터를 입력합니다."</span><span class="p">);</span>
    <span class="cm">/* 10건만 등록해보자 */</span>
    <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nx">len</span><span class="o">=</span><span class="mi">10</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span><span class="p">;</span><span class="nx">i</span><span class="o">++</span><span class="p">){</span>
        <span class="nx">AddressBook</span><span class="p">.</span><span class="nx">insert</span><span class="p">(</span><span class="nx">fixtures</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
    <span class="p">}</span>
<span class="p">}</span>

});

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