This is the first time when I have .net core and MongoDB usually use Entity Framework ORM. I use .net core 3 and MongoDB driver 2.11 to work with the database.
Here is an example of a repository service:
public class Repository<T> : IRepository<T> where T : IDocument
{
private readonly IMongoCollection<T> _collection;
public Repository(IDatabaseSettings settings)
{
var client = new MongoClient(settings.ConnectionString);
var database = client.GetDatabase(settings.DatabaseName);
_collection = database.GetCollection<T>(GetCollectionName(typeof(T)));
}
Task<T> FindOneAsync(Expression<Func<T, bool>> filterExpression){}
Task<T> FindByIdAsync(string id){}
Task InsertOneAsync(T document) {}
Task InsertManyAsync(ICollection<T> documents){}
Task ReplaceOneAsync(T document) {}
Task DeleteOneAsync(Expression<Func<T, bool>> filterExpression){}
Task DeleteByIdAsync(string id) {}
Task DeleteManyAsync(Expression<Func<T, bool>> filterExpression){}
}
As you can see this is a standard definition of repository class.
My question is when the repository works with a specific collection does all collection is loaded to local memory?
For example, if I want to find a specific document in the collection, then GetCollection in constructor fetching collection from database and running on all documents in the collection locally?
Or does it generate a query and execute it in a database similarly to Entity Framework ORM?