小编Kaz*_*aze的帖子

Java MongoDb获取id作为时间戳但需要十六进制字符串

我正在为名为 Schema 的集合执行 CRUD,并且需要将 de _id 作为十六进制字符串检索,但是当我使用 collection.find() 时,我得到的是时间戳和日期而不是字符串。

我收到这个结构:

{
"_id": {
            "timestamp": 1604689898,
            "date": "2020-11-06T19:11:38.000+00:00"
        }
}
Run Code Online (Sandbox Code Playgroud)

但我需要这样的东西:

{
"_id": "5fa5a085a4b09b307d53ed57"
}
Run Code Online (Sandbox Code Playgroud)

这是我的配置

Pom.xml

{
"_id": {
            "timestamp": 1604689898,
            "date": "2020-11-06T19:11:38.000+00:00"
        }
}
Run Code Online (Sandbox Code Playgroud)

MongoClient配置

{
"_id": "5fa5a085a4b09b307d53ed57"
}
Run Code Online (Sandbox Code Playgroud)

模式模型

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>co.com.itau</groupId>
    <artifactId>crypto-mongodb-java-ms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>crypto-mongodb-java-ms</name>
    <description>Microservice to save and read data from mongoDB using CSFLE</description>

    <properties>
        <java.version>1.8</java.version>
        <version.fabric8-maven-plugin>3.5.41</version.fabric8-maven-plugin>
        <swagger.version>3.0.0</swagger.version> …
Run Code Online (Sandbox Code Playgroud)

java spring pojo mongodb

5
推荐指数
1
解决办法
1743
查看次数

标签 统计

java ×1

mongodb ×1

pojo ×1

spring ×1