npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@eloquentjs/mongodb

v0.0.3

Published

MongoDB driver for EloquentJS

Readme

@eloquentjs/mongodb

MongoDB driver for EloquentJS. Use the same Eloquent API against MongoDB collections.

npm install @eloquentjs/core @eloquentjs/mongodb

Setup

import { connect } from '@eloquentjs/mongodb'
import { Model } from '@eloquentjs/core'

await connect({
  url:      process.env.MONGO_URL      ?? 'mongodb://localhost:27017',
  database: process.env.MONGO_DATABASE ?? 'myapp',
  // Optional auth
  username: process.env.MONGO_USERNAME,
  password: process.env.MONGO_PASSWORD,
})

class User extends Model {
  static table = 'users'   // maps to MongoDB collection name
}

await User.create({ name: 'Alice' })
await User.where('active', true).get()
await User.find('64a7f...')   // ObjectId string

MongoDB-Specific Features

// ObjectId handling — _id is automatically mapped to 'id'
const user = await User.find('64a7f3b2c1a2b3c4d5e6f7a8')
console.log(user.id)  // '64a7f3b2c1a2b3c4d5e6f7a8'

// Nested document queries
await User.where('address.city', 'New York').get()
await User.where('settings.theme', 'dark').get()

// Array contains
await User.where('tags', 'javascript').get()
await User.whereJsonContains('permissions', 'admin').get()

// Text search (requires text index on collection)
await User.whereRaw({ $text: { $search: 'Alice' } }).get()

// Geospatial (raw query)
await User.whereRaw({
  location: {
    $near: { $geometry: { type: 'Point', coordinates: [-73.9, 40.7] }, $maxDistance: 5000 }
  }
}).get()

Using with Multiple Connections

import { connect } from '@eloquentjs/mongodb'
import { connect as pgConnect } from '@eloquentjs/pgsql'

// Connect both drivers
await pgConnect({ host: 'localhost', database: 'app' })
const mongoConn = await connect({ url: 'mongodb://localhost', database: 'analytics' })

// Use MongoDB for specific models
class PageView extends Model {
  static connection = mongoConn
  static table      = 'page_views'
}

// Other models still use PostgreSQL
class User extends Model {
  static table = 'users'
}

Schema (Collections & Indexes)

MongoDB is schemaless, but you can manage indexes:

import { Schema } from '@eloquentjs/core'

await Schema.create('users', col => {
  col.index('email', { unique: true })
  col.index({ name: 'text', bio: 'text' })   // text index
  col.index({ location: '2dsphere' })         // geo index
  col.index(['tenant_id', 'created_at'])      // compound index
})

await Schema.dropIfExists('old_collection')
await Schema.hasTable('users')

Configuration Reference

| Option | Default | Description | |---|---|---| | url | mongodb://localhost:27017 | MongoDB connection URL | | database | — | Database name (required) | | username | — | Auth username | | password | — | Auth password | | authSource | admin | Auth database | | tls | false | Enable TLS | | replicaSet | — | Replica set name | | maxPoolSize | 10 | Max connection pool size |


License

MIT