Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 717 Bytes

File metadata and controls

29 lines (21 loc) · 717 Bytes

Spring Data With Mongo

Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>de.flapdoodle.embed</groupId>
    <artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>

String

Mongo prefers strings as data ype, so we change our id from Long to String.

LocalDateTime

Mongodb removed the nanosecond information from Date type and has a precision of milliseconds.

We can truncate LocalDateTime in Java:

Clock millisecondClock = Clock.tick(Clock.systemDefaultZone(), Duration.ofNanos(1000000)); 
LocalDateTime d = LocalDateTime.now(millisecondClock);