Technology used: Spring-Boot, MongoDB
Problem Statement:
Instead of having POJO with @Document
, and then writing RestController API and Repository using models, I want to have RequestBody with JSONObject
. I want to persist this JSON into particular collection in mongodb
.
Normally, we would specify @Document(collection="collName")
on the POJO Class, but I want to test on JSONObject
itself,
how do I achieve to write it to particular collection in mongodb
without specifying the collection it creates new collection with JSONObject
name and stores in it.
i.e. If in Restcontroller API, I write this,
JSONObject jsonObj = new JSONObject(string);
then, it will create collection with name jsonObj