https://github.com/doytowin/doyto-query-mongodb
It seems pretty easy to create a CRUD application for MongoDB.
@AutoConfigureMockMvc
@SpringBootTest(properties = {"spring.mongodb.embedded.version=5.0.5"})
class InventoryMvcTest {
@Resource
protected MockMvc mockMvc;
@BeforeAll
static void beforeAll(@Autowired MockMvc mockMvc) throws Exception {
String data = "[" +
" {\"item\": \"journal\", \"qty\": 25, \"size\": {\"h\": 14, \"w\": 21, \"uom\": \"cm\"}, \"status\": \"A\"}," +
" {\"item\": \"notebook\", \"qty\": 50, \"size\": {\"h\": 8.5, \"w\": 11, \"uom\": \"in\"}, \"status\": \"A\"}," +
" {\"item\": \"paper\", \"qty\": 100, \"size\": {\"h\": 8.5, \"w\": 11, \"uom\": \"in\"}, \"status\": \"D\"}," +
" {\"item\": \"planner\", \"qty\": 75, \"size\": {\"h\": 22.85, \"w\": 30, \"uom\": \"cm\"}, \"status\": \"D\"}," +
" {\"item\": \"postcard\", \"qty\": 45, \"size\": {\"h\": 10, \"w\": 15.25, \"uom\": \"cm\"}, \"status\": \"A\"}" +
"]";
mockMvc.perform(post("/inventory/").content(data).contentType(MediaType.APPLICATION_JSON));
}
@Test
void queryExamples() throws Exception {
mockMvc.perform(get("/inventory/?itemContain=book"))
.andExpect(jsonPath("$.data.total").value(1));
mockMvc.perform(get("/inventory/?status=A"))
.andExpect(jsonPath("$.data.total").value(3));
mockMvc.perform(get("/inventory/?size.hLt=12&status=A"))
.andExpect(jsonPath("$.data.total").value(2))
.andExpect(jsonPath("$.data.list[*].item",
containsInRelativeOrder("notebook", "postcard")));
mockMvc.perform(get("/inventory/?size.uom=in"))
.andExpect(jsonPath("$.data.total").value(2))
.andExpect(jsonPath("$.data.list[*].item",
containsInRelativeOrder("notebook", "paper")));
}
}