A flexible MongoDB fast connection framework built on top of Morphia.
- 🏭 Factory-Based Configuration
- Simple connection setup via
MongoDBConnectionConfigFactory
- Simple connection setup via
dependencies {
implementation("net.legacy.library:mongodb:1.0-SNAPSHOT")
}
1️⃣ Create Connection
MongoDBConnectionConfig config = MongoDBConnectionConfigFactory.create(
"mydb",
"mongodb://localhost:27017/",
UuidRepresentation.STANDARD
);
Datastore datastore = config.getDatastore();
2️⃣ Define Entity
@Entity("users")
public class User {
@Id
private ObjectId id;
private String name;
private int age;
// Getters and setters
}
3️⃣ Perform Operations
// Save entity
User user = new User("John", 25);
datastore.save(user);
// Query entity
List<User> users = datastore.find(User.class)
.filter(Filters.eq("name", "John"))
.iterator()
.toList();
MongoDBConnectionConfig
: Central configuration class- Custom client settings
- Connection lifecycle management
MongoDBConnectionConfigFactory
: Factory for creating configurations- Support for custom MongoDB settings
- UUID representation handling
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost:27017"))
.uuidRepresentation(UuidRepresentation.STANDARD)
.build();
MongoDBConnectionConfig config = MongoDBConnectionConfigFactory.create(settings);
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Made with ❤️ by LegacyLands Team