Giter VIP home page Giter VIP logo

Comments (3)

alexandre-spieser avatar alexandre-spieser commented on May 24, 2024 1

The next release will do this natively:

7f126a0

from mongodb-generic-repository.

artemiusgreat avatar artemiusgreat commented on May 24, 2024

Figured this out. Created method that works as AddManyAsync but uses GetCollection directly instead of HandlePartitioned. In this case we can specify different collection name in Mongo DB for the same model / class / type in C#.

public class CStorage<T> : BaseMongoRepository, IStorageService<T>
{
  public CStorage() : base(
    ConfigurationManager.AppSettings["MongoConnection"],
    ConfigurationManager.AppSettings["MongoStorage"])
  {
  }

  public async Task AddPartitionsAsync<TDocument>(IEnumerable<TDocument> documents, string partitionKey = null) where TDocument : IDocument
  {
    if (documents.Any())
    {
      documents.ForEach(o => FormatDocument(o));
      await GetCollection<TDocument>(partitionKey).InsertManyAsync(documents);
    }
  }
}

from mongodb-generic-repository.

alexandre-spieser avatar alexandre-spieser commented on May 24, 2024

Glad you solved your issue :)

Yes AddMany does not support insertion of documents with different PartitionKey values.

You could however try:

            foreach(var group in documents.GroupBy(e => e.PartitionKey))
            {
                repo.AddMany<DocType, TKey>(group);
            }

I have not tested this but it should theoretically work.
That way you cannot mistakenly insert docs in the wrong partition.
I hope this helps :)

from mongodb-generic-repository.

Related Issues (20)

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.