MongoDB: Spring Boot (Java)

Accessing MongoDB via Spring Boot

This repo has a demo:

See also:

Setting up Spring Boot with MongoDB

Setting up the data object

The first step is to set up a plain old java object that:

package edu.ucsb.cs56.pconrad.mlab.mlabdemo;

import lombok.Data;
import lombok.RequiredArgsConstructor; // generates constructor for fields marked with @NonNull                              
import lombok.NoArgsConstructor;  // @NonNull property ignored by this constructor                                                                                            
import lombok.NonNull;
import org.springframework.data.annotation.Id;

@Data
@NoArgsConstructor
@RequiredArgsConstructor
public class BuildingCode {

    @Id private String id;
    @NonNull private String code;
    @NonNull private String name;
}

More on MongoDB: Spring Boot (Java)