This project has moved. For the latest updates, please go here.
1

Closed

Expose FindAndModify method

description

I've often found myself needing this method on collections when I want to update a document but don't already have the document, only the ID and field I want to modify. I know I can access the Collection instance through the Repository but I'd rather it was exposed properly so I could avoid tightly coupling with the driver if possible which is the reason to use this project.
Closed Dec 26, 2014 at 11:38 AM by RobIII
Okidoki :-)

comments

RobIII wrote Aug 21, 2014 at 2:18 PM

Exposing a FindAndModify will still cause tightly coupling IMHO; this method does, again IMHO, not belong in a Repository Pattern. We try to avoid as much coupling to Mongo in itself (be it the driver or the underlying Mongo-specific "quirks"). So as far as I am concerned I'm afraid this method (e.g. your requiest) won't be implemented. But, as always, I'm open for discussion or possibly "community voting".

fbrooke wrote Aug 30, 2014 at 10:31 PM

I was thinking perhaps an overload for the Update method that takes an Id and maybe a Dictionary of fields to update, which would use FindAndModify internally. How does that sound?

RobIII wrote Sep 5, 2014 at 7:35 PM

I don't like it much; sorry ;-)

I'll try to explain why:

First; it relies on strings. It can't be statically compiled. There's no way to, compile-time, check if property "foo" exists.

Second: It won't allow me to update properties of different types (int/datetime/string) unless the dictionary is a more convoluted container of some type.

Third: it doesn't belong in a repository abstraction / implementation IMHO. The whole point of this project is to "hide" the Mongo-specific details as much as possible so you could, in the future, switch to another backend that also implements a repository(-like) interface without too much hassle (maybe a little 'glue' layer).

RobIII wrote Sep 5, 2014 at 7:37 PM

But; why do you use MongoRepository in this scenario at all? Why not simply talk directly to the (superb) Mongo-C# driver that MongoRepository uses internally as well?

fbrooke wrote Dec 26, 2014 at 10:01 AM

I agree, you can close this issue.

wrote Dec 26, 2014 at 11:38 AM