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

home2 게시판 Next.js 게시판 상세페이지 만들기 1 강의 dynamic route

상세페이지 만들기 1 강의 dynamic route

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

    jh
    참가자
    forum - app - deatail - [어쩌고]
    폴더의 page.js
    import { connectDB } from "@/util/database"
    import { ObjectId } from "mongodb"
    export default async function Detail(props){
       const db = (await connectDB).db("forum")
       let result = await db.collection('post').findOne({
          _id: new ObjectId(props.params.id)
      })
      
      console.log(props)
       if (!result) {
          return <div>게시물을 찾을 수 없습니다</div>
       }
       return (
          <div>
             <h4>상세페이지</h4>
             <h4>{result.title}</h4>
             <p>{result.content}</p>
          </div>
       )
    }
    여기서 ObjectId 가 선언되어도 컴파일 언어에서 못읽는 다고 하는데 해결법이 있을까요
    
    
    
    'ObjectId'의 시그니처 '(inputId: number): ObjectId'은(는) 사용되지 않습니다.ts(6387)
    bson.d.ts(1239, 8): 선언이 여기에 사용되지 않음으로 표시되었습니다.
    (alias) new ObjectId(inputId: number): ObjectId (+6 overloads)
    import ObjectId
    Create ObjectId from a number.
    @param inputId — A number.
    @deprecated — Instead, use static createFromTime() to set a numeric value for the new ObjectId.
    
    
    
    
    
    
    위가 경고문이고 @deprecated 살펴보면 해당 모듈의 컴파일은 이렇게 되어있습니다
     
    
    
    
    
    export declare class ObjectId extends BSONValue {
        get _bsontype(): 'ObjectId';
        /* Excluded from this release type: index */
        static cacheHexString: boolean;
        /* Excluded from this release type: buffer */
        /* Excluded from this release type: __id */
        /**
         * Create ObjectId from a number.
         *
         * @param inputId - A number.
         * @deprecated Instead, use `static createFromTime()` to set a numeric value for the new ObjectId.
         */
        constructor(inputId: number);
        /**
         * Create ObjectId from a 24 character hex string.
         *
         * @param inputId - A 24 character hex string.
         */
        constructor(inputId: string);
        /**
         * Create ObjectId from the BSON ObjectId type.
         *
         * @param inputId - The BSON ObjectId type.
         */
        constructor(inputId: ObjectId);
        /**
         * Create ObjectId from the object type that has the toHexString method.
         *
         * @param inputId - The ObjectIdLike type.
         */
        constructor(inputId: ObjectIdLike);
        /**
         * Create ObjectId from a 12 byte binary Buffer.
         *
         * @param inputId - A 12 byte binary Buffer.
         */
        constructor(inputId: Uint8Array);
        /** To generate a new ObjectId, use ObjectId() with no argument. */
        constructor();
        /**
         * Implementation overload.
         *
         * @param inputId - All input types that are used in the constructor implementation.
         */
        constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
        /**
         * The ObjectId bytes
         * @readonly
         */
        get id(): Uint8Array;
        set id(value: Uint8Array);
        /** Returns the ObjectId id as a 24 lowercase character hex string representation */
        toHexString(): string;
        /* Excluded from this release type: getInc */
        /**
         * Generate a 12 byte id buffer used in ObjectId's
         *
         * @param time - pass in a second based timestamp.
         */
        static generate(time?: number): Uint8Array;
        /**
         * Converts the id into a 24 character hex string for printing, unless encoding is provided.
         * @param encoding - hex or base64
         */
        toString(encoding?: 'hex' | 'base64'): string;
        /** Converts to its JSON the 24 character hex string representation. */
        toJSON(): string;
        /* Excluded from this release type: is */
        /**
         * Compares the equality of this ObjectId with `otherID`.
         *
         * @param otherId - ObjectId instance to compare against.
         */
        equals(otherId: string | ObjectId | ObjectIdLike | undefined | null): boolean;
        /** Returns the generation date (accurate up to the second) that this ID was generated. */
        getTimestamp(): Date;
        /* Excluded from this release type: createPk */
        /* Excluded from this release type: serializeInto */
        /**
         * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
         *
         * @param time - an integer number representing a number of seconds.
         */
        static createFromTime(time: number): ObjectId;
        /**
         * Creates an ObjectId from a hex string representation of an ObjectId.
         *
         * @param hexString - create a ObjectId from a passed in 24 character hexstring.
         */
        static createFromHexString(hexString: string): ObjectId;
        /** Creates an ObjectId instance from a base64 string */
        static createFromBase64(base64: string): ObjectId;
        /**
         * Checks if a value can be used to create a valid bson ObjectId
         * @param id - any JS value
         */
        static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
        /* Excluded from this release type: toExtendedJSON */
        /* Excluded from this release type: fromExtendedJSON */
        /**
         * Converts to a string representation of this Id.
         *
         * @returns return the 24 character hex string representation.
         */
        inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
    }
    
    #123090

    codingapple
    키 마스터
    mongodb 라이브러리나 bson 라이브러리 버전문제같은데 mongodb 라이브러리 지우고 mongodb@5 설치해봅시다
    기능은 잘되면 냅둬도 상관없습니다
    
    
    		
    	
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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