Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethink forwarding pattern from MongoCollection to MongoDatabase to Mongo #34

Open
tinchodias opened this issue Apr 22, 2018 · 4 comments

Comments

@tinchodias
Copy link
Contributor

If you see in current master, there are at least 8 cases of this pattern:

MongoCollection>>
commandInsert: newDictionary writeConcern: aConcern
	"Insert using Mongo command. Answer the output of the command.
	See more on https://docs.mongodb.com/manual/reference/command/insert/"

	^database commandInsert: newDictionary collection: name writeConcern: aConcern

where the API of MongoCollection correctly exposes a behavior of a collection in mongodb, and always the implementations is just "forwarding" (may be not the correct word) the message to the MongoDatabase adding some parameter.

Another example, extended:

MongoCollection>>
insert: aCollection
	database insert: aCollection collection: name

MongoDatabase>>
insert: aCollection collection: aString 
	root insert: aCollection collection: name , '.' , aString

as you can see, the MongoDatabase also forwards the message to root (an instance of Mongo).

This is not only a pattern that means annoying code... IMHO, the fact that a database contains collections doesn't imply that MongoDatabase should be a kind of facade or mediator between MongoCollection and Mongo. I think MongoCollection could send messages directly yo Mongo.

Also, MongoDatabase and MongoCollection belong to a same abstraction level. Only Mongo is more low-level stuff because it reads and writes to the socket that connects to mongodb.

Finally, a proposal to fix it: let MongoCollection know the root (Mongo instance) and not only the MongoDatabase. This:

MongoCollection>>
insert: aCollection
	root insert: aCollection collection: self database name , '.' , self name
@noha
Copy link
Contributor

noha commented Apr 28, 2019

What is the current status?

@tinchodias
Copy link
Contributor Author

I still have the same question. Do you have any opinion? I can create PR this week.

@tinchodias
Copy link
Contributor Author

Update: Now that I worked on the MongoClient (in #68), I suspect MongoDatabase and MongoCollection fit much better at the level of this SDAM package instead of the more lower-level Mongo model.

@noha
Copy link
Contributor

noha commented Aug 6, 2021

Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants