0

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

Community
  • 1
  • 1
cpDi
  • 1
  • 1
  • Hey, Welcome to SO. The community here will be able to help more if you can describe the problem you are facing more clearly and the solution that you have tried, preferably with code snippets. This should help - https://stackoverflow.com/help/how-to-ask – Dhawal Kapil Apr 02 '20 at 18:32
  • Not sure I fully got the question, but check this [post](https://stackoverflow.com/q/42414558/5873923) for a possible hint about working with the json string in a rest controller. – Marc Tarin Apr 03 '20 at 07:04

0 Answers0