neoxic / lua-mongo

MongoDB Driver for Lua
MIT License
141 stars 38 forks source link

Session support #36

Open gil-opplane opened 3 years ago

gil-opplane commented 3 years ago

Hey,

I've been looking at the code you implemented and, first of all, thanks for all the work. Now, I have a task at hand where I need to use a transaction to create multiple collections and commit or abort depending on the jobs' success. This should be available on the latest mongo version (4.4), so I went searching for the class in your code where the notion of transaction or session was implemented. Unfortunately, I didn't find them.

Am I missing something? Or, if not, are you planning on implementing these notions soon?

Here's the documentation I've been looking at:

Thanks in advance.

neoxic commented 3 years ago

First, I'll answer your questions directly: 1) No, there's no direct support for client sessions in lua-mongo; 2) No, there are no plans to implement this API along with other rarely used features.

Now, on a positive note, Mongo C Driver like all other MongoDB drivers/clients is just a wrapper around MongoDB's wire protocol. The protocol of MongoDB is essentially BSON objects going back and forth. A driver provides some basic functionality that helps the user to avoid handling basic I/O, constructing commands and parsing responses themselves. Please note that different drivers have a different level of abstraction dealing with this task. For example, the PHP driver handles most high level abstractions like instances, objects, sessions, etc. itself without relying on the underlying C driver (mongo-c-driver). There are drivers that imple

There's a generic client:command() in lua-mongo that you can use to implement nearly all other commands and queries. In particular, take a look here for the underlying mechanics of Server Sessions: https://docs.mongodb.com/manual/reference/server-sessions/

gil-opplane commented 3 years ago

Hi,

I'll look into the :command() method. I'm already using it in other parts with other tasks, I was just looking whether there was an easier way to do this through a direct method. Thanks nonetheless.

neoxic commented 3 years ago

I'm in favour to leave this issue open to see if there's demand for this feature and it's worth implementing it in the long run.

gil-opplane commented 3 years ago

Hi,

Sure, thanks. I'll see what I can do on my side, but I'll keep a close look on this.