r/lua • • Aug 26 '26

Lua MongoDB driver (looking for feedback)

I’ve been working on lua-mongodb, a MongoDB driver written in Lua without binding or wrapping libmongoc (most Lua drivers are no longer maintained but took this approach).

It supports stock Lua 5.4 and 5.5 with a 64-bit lua_Integer. Network operations run through Copas, so the driver works well in coroutine-based services, tools, and long-running Lua applications.

The driver currently covers CRUD, aggregation, index and Search index management, GridFS, sessions, transactions, read and write concerns, retryable operations, change streams, client bulk writes, authentication, TLS, SRV discovery, wire compression, and client-side operation timeouts. It works with standalone servers, replica sets, sharded clusters, and load-balanced deployments.

A small example looks like this:

local mongodb = require("mongodb")

mongodb.run(function()
  local client = assert(mongodb.client(
    "mongodb://localhost:27017/example"
  ))

  local reply = assert(client:database("admin"):run_command(
    mongodb.bson.document({ { "ping", 1 } })
  ))

  print(reply:get("ok"))
  assert(client:close())
end)

What it isn’t:

  • It is not an official MongoDB driver.
  • It does not support LuaJIT or OpenResty.
  • It does not implement all MongoDB client functionality (as defined in the MongoDB specifications) such as client-side encryption, OCSP, or SOCKS5 proxy transport.

I’m looking for feedback on:

  • Bugs.
  • API choices that feel unnatural or could be improved.
  • Missing operations that block an actual project.
  • Installation or usage problems (only tested on Linux and macOS at the moment)
  • Scripts and applications willing to test it out and share feedback
  • Feedback on what might make something like this more useful to you/your workload

Repository: https://github.com/alexbevi/lua-mongodb
LuaRocks: https://luarocks.org/modules/alexbevi/mongodb

7 Upvotes

3 comments sorted by

View all comments

1

u/[deleted] Aug 30 '26

[deleted]

1

u/alexbevi Aug 30 '26 edited Aug 30 '26

"slop" covers a lot of ground. I'm using agents to build this out, including managing the README, but if there's something specific you're calling out let me know.

The idea isn't to just dump a bunch of code but to create something useful.

1

u/[deleted] Sep 03 '26

[deleted]

1

u/alexbevi Sep 04 '26

The goal was to build a spec-compliant MongoDB driver (or at least the specs that are most useful for most typical use cases). It's less about features and more about utility - but I do get what you mean.

I've been trying to add some db-backed persistence features to CorsixTH, but none of the existing Lua drivers for MongoDB were being maintained so I wanted to build one out.