A. S.
A. S.

Reputation: 153

Meteor.users is undefined

I got an error saying

TypeError: Cannot read property 'insert' of undefined

when I run my application, and I discovered that the undefined thing mentioned before is "Meteor.users"

as it's used to insert some data to the database like so (that is the cause of the error):

  var tomId = Meteor.users.insert({username: "Tom",
    profile: { name: 'Tom Coleman', username:"Tom" }
  });

and I don't know how to make it work normally without being undefined

any help ?

Upvotes: 0

Views: 236

Answers (1)

Mostafiz Rahman
Mostafiz Rahman

Reputation: 8562

To create a new user in your application's users collection the easiest and safest way is to add accounts-base package first and then using it's API.

Add accounts-base by

meteor add accounts-base

Then what you need to do is:

import { Accounts } from 'meteor/accounts-base';

//now create your user
Accounts.createUser({
      username: YOUR_USERNAME,
      email: EMAIL_ADDRESS,
      password: PASSWORD,
      profile: {
          // WHATEVER OBJECT
      }
});

Upvotes: 1

Related Questions