
	                	                 MongoDBBSONDecimal128::serialize() 함수는 decimal128 타입의 숫자를 BSON 형식으로 serialize 할 때 오류가 발생할 수 있습니다.
이 문제는 MongoDBBSONDecimal128::serialize() 함수가 decimal128 타입의 숫자를 serialize 할 때, MongoDB의 버전과 호환성 문제로 인해 발생할 수 있습니다.
해결 방법은 MongoDBBSONDecimal128::serialize() 함수 대신, MongoDBBSONDecimal128::to_string() 함수를 사용하여 decimal128 타입의 숫자를 문자열로 변환한 다음, serialize() 함수를 사용하여 BSON 형식으로 serialize 할 수 있습니다.
다음은 예제 코드입니다.
#hostingforum.kr
cpp
#include 
#include 
#include 
#include 
int main() {
    mongocxx::instance inst{};
    mongocxx::client conn{mongocxx::uri{}};
    bsoncxx::builder::stream::document doc = {};
    doc << "num" << 12345678901234567890;  // decimal128 타입의 숫자
    bsoncxx::document::view bson_doc = doc.view();
    // decimal128 타입의 숫자를 문자열로 변환
    std::string decimal_str = bsoncxx::to_string(bson_doc["num"].get_decimal128());
    // serialize() 함수를 사용하여 BSON 형식으로 serialize
    bsoncxx::document::value bson_value = conn["test"]["num"].insert_one(
        bsoncxx::document::view{std::string("num").append(decimal_str)}).context("insert failed");
    return 0;
}
이 예제 코드에서는 decimal128 타입의 숫자를 문자열로 변환한 다음, serialize() 함수를 사용하여 BSON 형식으로 serialize합니다.
2025-06-30 01:58