2014-01-24 63 views
1

下面是我的示例代碼,如果運行這段代碼DB沒有定義錯誤是來如何解決這個error.But我在緊張的用戶詳細信息正在店mongoDb提交後的形式。而發送mongodb命令提示符操作.Plz幫我任何身體.....DB沒有被定義使用`流星Js`在`mongoDB`錯誤

user = new Meteor.Collection('test'); 

//Metro Client 

if (Meteor.isClient) { 

    Template.hello.events({ 
    'submit #loginform' : function (e , t) 
{ 
     e.preventDefault(); 
     var username = t.find('#username').value; 
      var password = t.find('#password').value; 
     var email=t.find('#email').value; 

    //Insert values Into mongodb 
      user.insert 
     ({ 
      username:username, 
      password: password, 
     email:email, 

     }); 
    j = { name : "username" } 
     db.test.insert(j); 
    console.log("username="+username); 
     console.log("password="+password); 
    console.log("email="+email); 
    } 
    }); 
// Send email is client 
Meteor.call('sendEmail', 
      '[email protected]', 
      '[email protected]', 
      'Hello from Meteor!'); 

} 

//Metro Server 

if (Meteor.isServer) { 
    Meteor.startup(function() { 

    }); 

// Send email is Server 

     Meteor.methods({ 
     sendEmail: function (to, from, subject, text) { 
     //console.log("email="+to); 
     process.env.MAIL_URL =  'smtp://[email protected]:****@smtp.gmail.com:587'; 

     check([to, from, subject, text], [String]); 
     this.unblock(); 
     Email.send({ 
      to: to, 
      from: from, 
      subject: subject, 
      text: text 
     }); 
     } 
    }); 


} 

回答

3

在蒙戈外殼,你會插入一個名爲「測試」像集合所以:

​​

在流星,你會插入到定義的集合如下:

Test = new Meteor.Collection('test'); 

用如下命令:

Test.insert(...); 

您的代碼假設對象db定義,就像它會在一個蒙古物殼。事實並非如此。您將需要行更改爲:

user.insert(j); 

使用流星,你不能發出從您的代碼蒙戈shell命令 - 你只能像Test集合對象進行操作。這些更改將反映在您的數據庫中。雖然meteor運行時,您可以通過在項目的根目錄,然後輸入打開一個新的終端看到這一點:

$ meteor mongo 

這將打開一個蒙戈外殼,您可以直接訪問類的數據:

db.test.findOne(); 

請注意,如果您使用meteor存儲用戶和密碼,則應該使用內置的accounts-password包。