2017-11-08 2 views
0

이 코드의 잘못된 점은 무엇입니까? "서버"폴더 안에 있습니다. 여기서 11 행은 오류 로그에서 호출됩니다.Meteor.users 컬렉션이 서버에서 정의되지 않았습니다.

import { Accounts } from 'meteor/accounts-base'; 
import generatePincode from '../../../utils/generate-pincode'; 
import Meteor from 'meteor/meteor'; 

Accounts.onCreateUser((options, user) => { 
    const customizedUser = Object.assign({ 
    'pincode': generatePincode(4), 
    }, user); 

    // check that the pincode doesn't already exist 
    const existingUser = Meteor.users.findOne({ 
    'pincode': customizedUser.pincode, 
    }); 
    if (existingUser) { 
    throw new Meteor.Error(500, 
     'Duplicate pincode generated, please try again.'); 
    } 

    // We still want the default hook's 'profile' behavior. 
    if (options.profile) { 
    customizedUser.profile = options.profile; 
    } 
    return customizedUser; 
}); 

터미널 (서버) 로그 :

Exception while invoking method 'createUser' TypeError: Cannot read property 'findOne' of undefined

+0

는 몽고 쉘 액세스 db.users입니까? – Jankapunkt

답변

2

가져 오기 유성 라인은 기본 또는 네임 스페이스 수출로 작업하는 것을 의미한다 올바르지 않습니다. 직접 유성을 얻기 위해이 시도

{ 
    Meteor: [Meteor object], 
    global: [Window on client and global on server], 
    meteorEnv: [env vars] 
} 

: 그것을 수정해야

import { Meteor } from 'meteor/meteor'; 

을 유성의 경우, 그건 당신이 가진 개체를 얻을 것을 의미합니다.

는, meteor remove accounts-passwordmeteor add accounts-password를 시도하지 않는 경우 다시