Giter VIP home page Giter VIP logo

mongo-extensions's People

Contributors

0xced avatar albyrock87 avatar glucaci avatar gmiserez avatar joslat avatar jtone123 avatar nscheibe avatar pascalsenn avatar timholzherr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongo-extensions's Issues

Method 'DropCollection' does not have an implementation.

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

Session / Transaction read and write concern configuration

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.

session.StartTransaction();

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.

NullRefException when trying to serialize/deserialize a null navigational property of a migrated entity

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:

value.Version = _context.Option.CurrentVersion;

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity E1 with a Migration
  2. Create another entity E2 that references E1 using a property E2.NavigationalProperty of type E1 and tag it with [BsonIgnoreIfNull]
  3. Create an instance of E2 and set E2.NavigationalProperty to null
  4. Persist it.
  5. Load the collection using an aggregate lookup/unwind

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)
  1. Notice a null ref exception is triggered when trying to materialize the result.

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):

  • OS: MacOS/Linux/Windows
  • Version : 3.0.0

Additional context
Add any other context about the problem here.

System.MissingMethodException

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

Simpler ways to configure collections

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:

  1. With a string parameter for only to configure the name of the collection.
  2. With the IMongoCollectionBuilder directly injected here. (Then we would not have to create an extra configuration class, if we dont want/need.

AddBsonClassMap<TMapDocument>() without Parameter

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

Vulnerability issues with

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

Index creation always executed during collection creation.

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.)

Provide an extension method for IServiceCollection to support other project types.

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

Query Logging Option

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)

Index creation enhancement

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.