Coder Social home page Coder Social logo

Comments (6)

mattcahill01 avatar mattcahill01 commented on June 12, 2024

Hi Guys (Rob :) ),
Any chance of some feedback?

from mongorepository.

RobThree avatar RobThree commented on June 12, 2024

MongoRepository is based on entire documents (entities) to be updated; simply pull the entity from Mongo, make your changes to the entity/document, and Update to save again.

If I misunderstood your question, then please post code to reproduce / demonstrate your problem.

from mongorepository.

mattcahill01 avatar mattcahill01 commented on June 12, 2024

I have ended up just adding this new method to the repo

///

    /// Upserts an entity.
    /// </summary>


    /// <param name="filter">The filter.</param>
    /// <param name="updateDefinition">The update definition.</param>
    public virtual void Update(FilterDefinition<T> filter, UpdateDefinition<T> updateDefinition)
    {
      var result = this.collection.UpdateOne(filter, updateDefinition);  
    }

from mongorepository.

RobThree avatar RobThree commented on June 12, 2024

...which is fine (for you / your project) but not for MongoRepository. The Update method you show above leaks mongo-specific stuff like FilterDefinition and UpdateDefinition. MongoRepository aims to stay as persistance-agnostic as possible so you could, in theory, easily swap it out for another persistance layer (as long as it implements the repository interface). MongoRepository's goal is to "narrow" the usage of the Mongo API, not enhance it. It aims to provide only the most basic operations (Get/Update/Delete/...) and no more so you won't be easily enticed to use mongo-specific stuff that later will be hard to change to another persistance layer. If you don't want that or don't need that you'd probably better use the mongo-csharp-driver directly.

Having said that: I would've probably implemented your method as an extension method.

from mongorepository.

mattcahill01 avatar mattcahill01 commented on June 12, 2024

Ah Right. Makes sense if that is the goal. I like to have a bit of both however - the nice abstracted repo but some Mongo specific goodies as well.

from mongorepository.

RobThree avatar RobThree commented on June 12, 2024

I understand; sometimes it's nice to have your cake and eat it too 😉 But consider using an extension method so you can easily 'upgrade' to a newer version of MongoRepository should it ever change/update.

from mongorepository.

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.