Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nodirbek-abdulaxadov/mongodbcore
MicroORM based on MongoDB.Driver
https://github.com/nodirbek-abdulaxadov/mongodbcore
Last synced: about 1 month ago
JSON representation
MicroORM based on MongoDB.Driver
- Host: GitHub
- URL: https://github.com/nodirbek-abdulaxadov/mongodbcore
- Owner: Nodirbek-Abdulaxadov
- License: mit
- Created: 2024-07-02T14:21:31.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-11-08T11:52:06.000Z (2 months ago)
- Last Synced: 2024-11-08T12:35:19.260Z (2 months ago)
- Language: C#
- Homepage:
- Size: 145 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# MongoDbCore
## Latest stable version 1.3.0
[`https://www.nuget.org/packages/MongoDbCore/`](https://www.nuget.org/packages/MongoDbCore/)
MongoDbCore is a lightweight micro-ORM for .NET designed to simplify interactions with MongoDB. It provides a straightforward API for performing common database operations, enabling developers to build applications quickly and efficiently.
## Key Features
- **Easy Setup**: Simple configuration to get started with MongoDB.
- **CRUD Operations**: Supports Create, Read, Update, and Delete operations seamlessly.
- **Asynchronous Support**: Perform database operations asynchronously for better performance.
- **Performance Optimizations**: Designed for efficient use of memory and speed.## Installation
To install MongoDbCore, add it to your project using NuGet:
```dotnet add package MongoDbCore```
## Getting Started
### Configuration
To configure MongoDbCore, follow these steps:
1. **Set Up Your MongoDB Connection**: Define your MongoDB connection string in your application settings.
```
"MongoDB": {
"Connection": "mongodb://localhost:27017",
"Database": "database_name",
"MaxConnectionPoolSize": 100 //default
}
```2. **Initialize MongoDbCore**: Configure the MongoDbCore context in your `Program.cs`:
```
// Setup the application and services
builder.Services.AddMongoDbContext(builder.Configuration
.GetSection("MongoDB")
.Get()!);
```### Create TodoEntity based on BaseEntity
Create a class that inherits from `MongoDbContext` to define your database context:
```
public class Todo : BaseEntity
{
public string Task { get; set; } = string.Empty;
}
```### Setting Up the Database Context
Create a class that inherits from `MongoDbContext` to define your database context:
```
public class AppDbContext(MongoDbCoreOptions options) : MongoDbContext(options)
{
public Collection Todos { get; set; } = null!;protected override async Task OnInitializedAsync()
{
// Initialize data if necessary
}
}
```### Basic CRUD Operations
MongoDbCore simplifies CRUD operations. Here's how you can use it:
#### Inject AppDbContext in your service class:
```
public class TodoService(AppDbContext dbContext)
{ }
```#### Create
To create a new entity:```
Todo newTodo = new();
dbContext.Todos.Add(newTodo);
```#### Read
To retrieve an entity:```
var todos = dbContext.Todos.ToList();
```#### Update
To update an existing entity:
```
var updateTodo = dbContext.Todos.FirstOrDefault();
dbContext.Todos.Update(updateTodo);
```#### Delete
To delete an entity:
```
var updateTodo = dbContext.Todos.FirstOrDefault();
dbContext.Todos.Delete(updateTodo);
```## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Contributing
Contributions are welcome! Please read the [CONTRIBUTING](CONTRIBUTING.md) guide for details on how to contribute to this project.