How does MongoRepository create a collection

  mongodb, question

Problem description

Business requirements need to be based on a certain field value, assuming the value isdemo(This value is unique) to create a file nameddemoCollection of. After that, the document information related to demo (the structure is fixed) will be stored in this collection.

The environmental background of the problem and what methods have you tried?

The main problems are:

  1. How do I use MongoRepository to create a database calleddemoA collection of?
  2. If it is createddemoCollection, but since the name and structure of this collection are only known at runtime, how to do entity class mapping to ensure the normal operation of subsequent CRUD operations?

I have thought about using reflection, but reflection can only create objects of classes, not classes, so there is still no way to unmap entity classes at runtime. And even if you can, once the server is shut down, all previously created entity classes will disappear.

Create a demo collection, which I understand as creating a demo object? If so, use it

-MongoRepository<demo,String > can be used for CRUD

# Supplement
I have tried, you can try it this way.
The general meaning is to use List<T > to control the number of multiple-choice and question-and-answer questions
Re-analyze the specific situations of multiple-choice questions and question-and-answer questions, such as questionnaire number, options, and the same train of thought List<String >

//Questionnaire Entity Class
 @Data
 @Document(collection = "t_question")
 public class Question {
 @Id
 private String id;
 //multiple choice questions
 @Field
 private List<T> chooseList;
 
 //short answer question
 @Field
 private List<T> saList;
 
 //index
 @Field
 @Indexed(name = "index_question", direction = IndexDirection.DESCENDING)
 private String index_question;
 }
// DAO layer
 public interface QuestionRepository extends MongoRepository<Question,String> {
 }
@Service
 public class QuestionService {
 @Autowired
 private QuestionRepository questionRepository;
 
 /**
 * save a single questionnaire
 * @param question Question entity class
 * @return saves results
 */
 public Question savePaper(Question question){
 return questionRepository.save(question);
 }
 }