NIAOJoin Beta
Ecosystem

nmongo

available

MongoDB Integration

Databases

Overview

nmongo talks to MongoDB from Niao. Connect with a URI, get a database handle, and work with collections as BSON documents, same mental model as the official drivers, just Niao-facing APIs.

It covers everyday CRUD, aggregation pipelines, index management, and multi-document transactions. GridFS is there for large blobs; change streams let you react to inserts and updates in real time instead of polling.

  • Connection pooling
  • BSON CRUD
  • Aggregation pipelines
  • Change streams

Import

import
import "nmongo"

Quick start

quick start
import "nmongo"
let db = nmongo.connect("mongodb://localhost:27017")
let users = db.collection("users")
users.insert_one({ name: "Niao", role: "admin" })

Capabilities

High-level overview of what nmongo is for.

Structured connect

Parse a connection string into pool size, timeouts, TLS, and auth settings instead of passing opaque flags around.

BSON CRUD

insert_one/many, find, find_one, update, delete, all take filter documents in the usual Mongo style.

Aggregation pipelines

Chain $match, $group, $lookup, $project, and the rest for reports and transforms server-side.

Indexes & transactions

Create and drop indexes. Run ACID transactions across multiple documents in a session when consistency matters.

Change streams

Watch a collection or database and get events as documents change, good for caches and sync jobs.

GridFS

Store files larger than the 16 MB doc limit, chunked with metadata, for uploads and media.

API reference

42 functions and methods in nmongo. Grouped by category from the standard library docs.

Connection

SignatureDescription
nmongo.connect(opts)Structured connect (preferred); credentials never logged
nmongo.connect_uri(uri)Connect via MongoDB URI
nmongo.close(client)Close client and invalidate handle
nmongo.ping(client)Server health check
nmongo.list_databases(client)Database names

CRUD

SignatureDescription
find(client, db, coll, filter?, opts?)All matching documents
find_one(...)First match or `nil`
insert_one(client, db, coll, doc)`{inserted_id}`
insert_many(client, db, coll, docs, opts?)`{inserted_ids}`
update_one/many(...)`{matched, modified, upserted_id?}`
replace_one(...)Same shape as update
delete_one/many(...)`{deleted_count}`
count_documents(...)Document count
distinct(client, db, coll, field, filter?)Distinct values array

Aggregation & indexes

SignatureDescription
aggregate(client, db, coll, pipeline, opts?)Aggregation pipeline
create_index(client, db, coll, keys, opts?)Returns index name
list_indexes(client, db, coll)Index metadata
drop_index(client, db, coll, name)Drop index
list_collections(client, db)Collection names
drop_collection(client, db, coll)Drop collection

Transactions

SignatureDescription
start_session(client)Session handle
start_transaction(session, opts?)Begin transaction
commit_transaction(session)Commit
abort_transaction(session)Abort
end_session(session)End session

GridFS

SignatureDescription
gridfs_upload(client, db, filename, data, opts?)Upload string or `byte_array`
gridfs_download(client, db, filename, opts?)Returns `byte_array`
gridfs_delete(client, db, filename, opts?)Delete by filename
gridfs_list(client, db, opts?)List files + metadata

Change streams

SignatureDescription
watch(client, db, coll, pipeline?, opts?)Returns watch handle (background thread)
watch_next(watch_id)Next event or `nil`
watch_close(watch_id)Stop stream

BSON helpers

SignatureDescription
object_id(hex)ObjectId for filters/inserts (`{$oid: "..."}`)
is_object_id(s)Validate hex string
to_extended_json(value)Niao value → extended JSON string
from_extended_json(s)Parse extended JSON → Niao value

Async

SignatureDescription
async_find(...)Background find
async_bulk_write(...)Background bulk insert loop
task_done(task)Poll completion
task_wait(task)Block until done
task_result(task)Result value or error
task_cancel(task)Cancel task

Notes

  • Long-running queries can be dispatched to background tasks so the VM stays responsive.

Related libraries

More from Databases.

available

npg

PostgreSQL Integration

PostgreSQL driver with connection pooling, migrations, prepared statements, LISTEN/NOTIFY, and COPY bulk load.

  • r2d2 pool
  • Schema migrations
  • Prepared statements
  • LISTEN/NOTIFY
Read more
available

nsqlite

SQLite Integration

Embedded SQLite: file-based databases, migrations, prepared statements, transactions, and batch inserts. WAL on by default.

  • WAL mode
  • Schema migrations
  • Prepared statements
  • Batch inserts
Read more