1

First, I will show you two pictures of data recorded in MongoDB Compass.

[User Collection]

enter image description here

[Plan Collection]

enter image description here

As you can see I get only 3 values ​​from the user in the User collection: name, phone and address. It is understood that _id is automatically generated through ObjectID when such information is received, but I do not know why _class is created. When _class contains user information that I created myself, class information for use is entered as a string value. ex) "com.example.User". Plan collection also receives 11 data from index to createdAt from the user, and _id is automatically generated through ObjectID. But here we get __v instead of _class, and this value will always exist as 0.

For reference, I did not implement the way the Plan Collection is saved, but I implemented the way the User Collection is saved through Spring boot.My Repository Interface looks like this:

@Repository
public interface UserRepository extends MongoRepository<User, String> {
}
  1. Is the creation of _class a result of using MongoRepository?
  2. Are __v or _class necessary values?
  3. How can I get rid of it if I don't need it?
  4. Can developers change the name themselves?
prasad_
  • 12,755
  • 2
  • 24
  • 36
H.JiMan
  • 269
  • 1
  • 2
  • 10
  • 1
    `_class` is meta-data used by Spring Data MongoDB to map the MongoDB collection document fields to the Java POJO class fields in your Spring application. I believe there are settings in Spring to work with it and its configuration. – prasad_ Jun 07 '21 at 09:08

0 Answers0