정의
바이너리 데이터 객체를 생성합니다.
BinData 의 구문은 다음과 같습니다:
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
행동
시스템의 엔디안 은 머신의 아키텍처에 따라 달라집니다. BSON 데이터의 숫자는 항상 리틀 엔디안 으로 저장되며, 시스템이 빅 엔디안 인 경우 숫자 데이터가 빅 엔디안과 리틀 엔디안 간에 변환됩니다.
비트 테스트 일치 표현식 연산자의 컨텍스트에서:
BinData values act as bitmasks and are interpreted as though they are arbitrary-length unsigned little-endian numbers. The lowest-addressable byte is always interpreted as the least significant byte. Similarly, the highest-addressable byte in the BinData is always interpreted as the most significant byte.
예시
BinData() 객체 삽입
BinData() 생성자를 사용하여 bdata 변수를 만듭니다.
var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")
객체를 testbin 컬렉션에 삽입합니다.
db.testbin.insertOne( { _id : 1, bin_data: bdata } )
삽입된 문서에 대해 testbin 컬렉션을 쿼리합니다.
db.testbin.find()
컬렉션에 저장된 바이너리 buffer를 볼 수 있습니다.
{ _id: 1, bin_data: Binary(Buffer.from("81fd547317474c9d8743f10642b3bb99", "hex"), 0) }
BinData() 객체의 길이 가져오기
BinData() 생성자를 사용하여 bdata 변수를 만듭니다.
var bdata = BinData(0, "gf1UcxdHTJ2HQ/EGQrO7mQ==")
.length()를 사용하여 객체의 비트 길이를 반환합니다.
bdata.length()
반환되는 값은 다음과 같습니다.
16