When creating data in MongoDB, there was an automatically generated value, how can I control it?

148 views Asked by At

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?
0

There are 0 answers