使用'Meteor Js'在'mongoDB'中未定义db错误`

使用'Meteor Js'在'mongoDB'中未定义db错误`,meteor,Meteor,下面是我的示例代码,如果运行此代码db未定义错误是如何解决此错误的。但我的紧张是用户详细信息在提交表单后存储在mongoDb中。并发送mongoDb命令提示操作。请帮助我任何人 user = new Meteor.Collection('test'); //Metro Client if (Meteor.isClient) { Template.hello.events({ 'submit #loginform' : function (e , t) { e.

下面是我的示例代码,如果运行此代码db未定义错误是如何解决此错误的。但我的紧张是用户详细信息在提交表单后存储在
mongoDb
中。并发送
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',
            'xxxx@.com',
            'yyyy@gmail.com',
            '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://AAAA@gmail.com:****@smtp.gmail.com:587'; 

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


}

在mongo shell中,您将插入一个名为“test”的集合,如下所示:

db.test.insert(...);
在meteor中,您将插入到定义如下的集合中:

Test = new Meteor.Collection('test');
使用如下命令:

Test.insert(...);
您的代码假设对象
db
已定义,就像在mongodb shell中一样。事实并非如此。您需要将该行更改为:

user.insert(j);
使用meteor时,不能从代码中发出mongo shell命令-只能对集合对象执行操作,如
Test
。这些更改将反映在数据库中。当meteor运行时,您可以在项目的根目录中打开一个新的终端并键入:

$ meteor mongo
这将打开一个mongo shell,您可以在其中直接访问数据,如:

db.test.findOne();

请注意,如果您使用meteor存储用户和密码,则应使用内置的
帐户密码
软件包