swisslife-oss / mongo-extensions Goto Github PK
View Code? Open in Web Editor NEWExtensions libraries for MongoDB.
Home Page: https://swisslife-oss.github.io/mongo-extensions/
License: MIT License
Extensions libraries for MongoDB.
Home Page: https://swisslife-oss.github.io/mongo-extensions/
License: MIT License
The c# mongodb driver has no simple function to enable the profiling of MongoDB's database.
Very convenient would be a method like EnableProfiling(...).
hi,
I am using only Mongo in my project and there is no problem but when both Mongo and Sql are used in the same project the following error is displayed.
Exception:
Unable to load one or more of the requested types.
Method 'DropCollection' in type 'MongoDB.Extensions.Transactions.MongoTransactionDatabase' from assembly 'MongoDB.Extensions.Transactions, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Thanks for your help
MongoDB has no optimistic concurrency handling out of the box.
Now, Jimmy Bogard has a blog post how it could be implemented.
https://jimmybogard.com/document-level-optimistic-concurrency-in-mongodb/
This would be a very nice enhancement for the MongoDB extensions.
Is your feature request related to a problem? Please describe.
Hello, thank you for open sourcing your Transactions extensions.
This is a feature request.
Describe the solution you'd like
At the moment, and as far as I can tell, there is now way to configure ClientSessionOptions or TransactionOptions.
Use case: https://www.mongodb.com/docs/v6.0/core/transactions/#read-concern-write-concern-read-preference
Describe alternatives you've considered
None.
Additional context
None.
Describe the bug
When trying to execute a lookup query to load navigational properties of a migrated entity, the query fails with a null ref exception.
This happens at this line:
To Reproduce
Steps to reproduce the behavior:
public class E1 : IEquatable<E1>, IVersioned
{
[BsonId]
public ObjectId Id { get; set; }
....
public int Version { get; set; }
}
public class E2 : IEquatable<E2>, IVersioned
{
[BsonId]
public ObjectId Id { get; set; }
[BsonElement("e1id")]
public ObjectId E1Id { get; set; }
[BsonIgnoreIfNull]
public E1? NavigationalProperty { get; set; }
public int Version { get; set; }
.....
}
public class E1Migration : IMigration
{
public int Version => 1;
public void Up(BsonDocument document)
{
document["newField"] = new BsonArray();
}
public void Down(BsonDocument document)
{
document.Remove("newField");
}
}
_e2collection
.Aggregate()
.Lookup("E1Collection", nameof(E2.E1Id), "_id", nameof(E2.NavigationalProperty))
.Unwind(nameof(E2.NavigationalProperty))
.As<E2>()
.Match(_ => true)
.ToListAsync(ct)
Expected behavior
Null values should not be serialized/deserialized if they are marked as [BsonIgnoreIfNull]. Bellow is the stack trace.
Stack Trace
System.NullReferenceException: Object reference not set to an instance of an object.
at MongoDB.Extensions.Migration.MigrationSerializer`1.Serialize(BsonSerializationContext context, BsonSerializationArgs args, T value)
at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Serialize(BsonSerializationContext context, BsonSerializationArgs args, Object value)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Serialize(IBsonSerializer serializer, BsonSerializationContext context, Object value)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.ToBsonValue(IBsonSerializer serializer, Object value)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateComparison(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateComparison(BinaryExpression binaryExpression)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate[TDocument](Expression`1 predicate, IBsonSerializer`1 parameterSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Linq2Implementation.LinqProviderAdapterV2.TranslateExpressionToFilter[TDocument](Expression`1 expression, IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.ExpressionFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
at MongoDB.Driver.PipelineStageDefinitionBuilder.<>c__DisplayClass34_0`1.<Match>b__0(IBsonSerializer`1 s, IBsonSerializerRegistry sr, LinqProvider linqProvider)
at MongoDB.Driver.DelegatedPipelineStageDefinition`2.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
at MongoDB.Driver.AppendedStagePipelineDefinition`3.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
at MongoDB.Driver.MongoCollectionImpl`1.AggregateAsync[TResult](IClientSessionHandle session, PipelineDefinition`2 pipeline, AggregateOptions options, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
hi,
When I run project, I see this exception in my context.
I check everything code I not found problem.
I did all the settings as per the documentation.
When is this error displayed?
Exception:
System.MissingMethodException: 'Method not found: 'MongoDB.Shared.Hasher MongoDB.Shared.Hasher.HashElements(System.Collections.IEnumerable)'.'
Thanks for your help
Current collection configuration needs always a separate configuration class per collection
At the moment the collections can only be configured in the way, that we have to create a configuration class (for each collection), which is inherited from the IMongoCollectionConfiguration interface. In this configuration class, we have to implement the OnConfiguring method. Afterwards, the configuration class has to be registered at the IMongoDatabaseBuilder.ConfigureCollection(...);
This is quite complex configuration process, especially if you have a simple case.... for example if you only want to set the name of the collection.
Feature request
What we would like to have, is the IMongoDatabaseBuilder.ConfigureCollection(...) method with the two overloads:
Hi,
With the Mongo API it is possible to call BsonClassMap.RegisterClassMap with and without an action.
In this extension package however there is only this method:
public IMongoCollectionBuilder<TDocument> AddBsonClassMap<TMapDocument>( Action<BsonClassMap<TMapDocument>> bsonClassMapAction) where TMapDocument : class
For a specific issue that we are currently encountering we need to register a class without any action.
Would you consider including a method AddBsonClassMap with the following declaration:
public IMongoCollectionBuilder<TDocument> AddBsonClassMap() where TMapDocument : class
We are unable to use this library due to Open Source security issues detected by our scanning tools. This library uses microsoft.aspnetcore.http.features.2.2.0.nupkg which references system.net.http.4.3.0.nupkg. This vulnerability is outlined here: CVE-2018-8292
During every collection creation with MongoDbContext, the index are checked if created or not (and creates it if not created). This should only occur ones, at the beginning. Otherwise it gets really slow if someone creates always a new collection for every call.
(Every collection creation a database connection is established and indexed checked. Slow for transient.)
Is your feature request related to a problem? Please describe.
Right now, the migration builder registration sequence uses the IApplicationBuilder interface as a starting point. While this is fine for ASP.NET projects, bootstrapping the migration builder in other project types, i.e Azure Functions, is not possible.
Describe the solution you'd like
Extend the IServiceCollection interface directly.
Describe alternatives you've considered
Copy the code from the library and refactor it to be used on an IServiceCollection interface.
Additional context
N/A
We could add a interface for query logging.
The idea would be to have insights in query structure and metrics during development (and maybe even in QA)
The parameterless AddBsonClassMap method is not added to the IMongoCollectionBuilder and cannot be used by the user.
Create an extended index function, which creates a new index when the index with the given name not exists OR it skips the index creation if the index with the given name already exists and all index settings (options) are the same.
However, if the index with the same name already exists, but the index settings (options) are different, then the existing index shall be dropped and newly created with the new settings (options).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.