1

Below is my sample code ,if run this code db not defined error is came how to to solve this error.But my in tension is user details are store in mongoDb after submit the form .And send the mongodb command prompt operations .Plz Help me any body.....

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
        });
      }
    });


}

1 Answer 1

3

In the mongo shell, you would insert into a collection called 'test' like so:

db.test.insert(...);

In meteor, you would insert into a collection defined as follows:

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

with a command like:

Test.insert(...);

Your code is assuming that the object db is defined, like it would be in a mongodb shell. It isn't. You would need to change the line to:

user.insert(j);

When using meteor, you can't issue mongo shell commands from your code - you can only perform operations on collection objects like Test. Those changes will then be reflected in your database. While meteor is running, you can see this by opening a new terminal in your project's root directory and typing:

$ meteor mongo

That will open a mongo shell where you can access the data directly like:

db.test.findOne();

Please note that if you are using meteor to store users and passwords, you should use the built-in accounts-password package.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.