Junior — Middle
Tell me about your experience working with the MongoDB database and how you interacted with it in projects
sobes.tech AI
Answer from AI
In projects with MongoDB, I interacted through the official Java driver and using Spring Data MongoDB. The main operations included:
- Connecting to the database and configuring connection parameters.
- Creating and using repositories for CRUD operations.
- Executing queries with filters and aggregations.
- Indexing collections to optimize queries.
Example of using Spring Data MongoDB:
@Document(collection = "users")
public class User {
@Id
private String id;
private String name;
private int age;
// getters and setters
}
public interface UserRepository extends MongoRepository<User, String> {
List<User> findByAgeGreaterThan(int age);
}
This approach allows working conveniently with documents as Java objects, simplifying development and maintenance.