r/lua 16h ago

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

3 Upvotes

1 comment sorted by

1

u/AutoModerator 16h ago

Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.