• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Next.js 게시판 유저 중복 이메일 체크 질문있습니다.

유저 중복 이메일 체크 질문있습니다.

6 글 보임 - 1 에서 6 까지 (총 6 중에서)
  • 글쓴이
  • #80673

    정중식
    참가자
          const user = await db.collection('user_card').findOne({ email });
          console.log(user);
     
    이렇게 하는거 맞을까요? 중복된 이메일인데 계속 null을 콘솔출력해줍니다.
    
    const user = await db.collection('user_card').find({ email });
    console.log(user);
    
    해주면 
    
     sessionPool: ServerSessionPool { client: [MongoClient], sessions: [List] },
        hasEnded: false,
        clientOptions: [Object: null prototype] {
          hosts: [Array],
          credentials: [MongoCredentials],
          compressors: [Array],
          connectTimeoutMS: 30000,
          dbName: 'test',
          directConnection: false,
          driverInfo: {},
          enableUtf8Validation: true,
          forceServerObjectId: false,
          heartbeatFrequencyMS: 10000,
          keepAlive: true,
          keepAliveInitialDelay: 120000,
          loadBalanced: false,
          localThresholdMS: 15,
          maxConnecting: 2,
          maxIdleTimeMS: 0,
          maxPoolSize: 100,
          minPoolSize: 0,
          minHeartbeatFrequencyMS: 500,
          monitorCommands: false,
          noDelay: true,
          pkFactory: [Object],
          raw: false,
          readPreference: [ReadPreference],
          retryReads: true,
          retryWrites: true,
          serverSelectionTimeoutMS: 30000,
          socketTimeoutMS: 0,
          srvMaxHosts: 0,
          srvServiceName: 'mongodb',
          waitQueueTimeoutMS: 0,
          zlibCompressionLevel: 0,
          useNewUrlParser: true,
          userSpecifiedAuthSource: false,
          userSpecifiedReplicaSet: false,
          srvHost: 'cluster0.ip8dsz4.mongodb.net',
          tls: true,
          mongoLoggerOptions: [Object],
          metadata: [Object],
          replicaSet: 'atlas-hdeny5-shard-0',
          [Symbol(@@mdb.enableMongoLogger)]: false
        },
        explicit: false,
        supports: { causalConsistency: false },
        clusterTime: undefined,
        operationTime: undefined,
        owner: [Circular *3],
        defaultTransactionOptions: {},
        transaction: Transaction {
          state: 'NO_TRANSACTION',
          options: {},
          _pinnedServer: undefined,
          _recoveryToken: undefined
        },
        [Symbol(kCapture)]: false,
        [Symbol(snapshotEnabled)]: false,
        [Symbol(serverSession)]: null,
        [Symbol(txnNumberIncrement)]: 0
      },
      [Symbol(filter)]: {},
      [Symbol(builtOptions)]: {
        raw: false,
        useBigInt64: false,
        promoteLongs: true,
        promoteValues: true,
        promoteBuffers: false,
        ignoreUndefined: false,
        bsonRegExp: false,
        serializeFunctions: false,
        fieldsAsRaw: {},
        enableUtf8Validation: true,
        readPreference: ReadPreference {
          mode: 'primary',
          tags: undefined,
          hedge: undefined,
          maxStalenessSeconds: undefined,
          minWireVersion: undefined
        }
      }
    }
    
    막 이런거 출력해줍니다.
     
    제가 뭘 잘못한건지 모르겠어요..
    #80700

    codingapple
    키 마스터
    하나찾을 땐 find말고 .findOne 씁시다
    #80734

    정중식
    참가자
    센센세 계속 null이 나옵니다.
    
    signup.js 파일에 제가 쓴 코드입니다.
    
    
    import { connectDB } from '@/util/database';
    import bcrypt from 'bcrypt';
    export default async function handler(req, res) {
      if (req.method === 'POST') {
        const { name, email, password } = req.body;
        try {
          let db = (await connectDB).db('forum');
          if (name === '' || email === '' || password === '') {
            return res.status(400).json('모든 칸을 입력해주세요');
          }
          const user = await db.collection('user_card').findOne({ email: email });
          console.log(user);
      
        } catch (error) {
          console.log('error:', error);
        }
      }
    }
    몽고디비에 저장되어있는건 다음 사진과 같아요
    
    
    왜 null 이 나오는건지이유를 모르겠어요..
    #80735

    정중식
    참가자
        const { name, email, password } = req.body;
    console.log(name,email,password); 
    다 정상 출력나오고있습니다.
    #80781

    codingapple
    키 마스터
    db.collection('user_card').는 오타인듯요
    #80804

    정중식
    참가자
    아..
    
    .. 
    감사합니다ㅋㅋㅋ..
6 글 보임 - 1 에서 6 까지 (총 6 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠