Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
72a2614
Switch to TypeScript
marshallswain Jul 16, 2025
967e300
feat: Update MongoDB compatibility and Node.js 12 support
marshallswain Jul 16, 2025
1f70f10
fix: Update dependencies to address security vulnerabilities
marshallswain Jul 16, 2025
ade483c
fix: Resolve remaining security vulnerabilities
marshallswain Jul 16, 2025
7d60244
feat: Improve TypeScript types and performance optimizations
marshallswain Jul 16, 2025
bcecee1
docs: Update README with TypeScript support and performance improvements
marshallswain Jul 16, 2025
ca39f9c
docs: Fix broken badges and add Mongoose version info
marshallswain Jul 16, 2025
8baceae
docs: Update Contributing section with modern development setup
marshallswain Jul 16, 2025
41027a9
chore: Remove unused Mongoose version test scripts
marshallswain Jul 16, 2025
856f0e8
ci: Fix GitHub Actions workflow for kerberos dependency
marshallswain Jul 16, 2025
accf863
ci: Fix kerberos compilation issues in CI
marshallswain Jul 16, 2025
1f1891f
chore: Remove unused run-rs dependency and clean up CI
marshallswain Jul 16, 2025
44bfccd
ci: Skip TypeScript build step in CI to focus on functional testing
marshallswain Jul 16, 2025
36f7699
fix: Add TypeScript build step back to CI and disable strict checking
marshallswain Jul 16, 2025
7cfc7a8
fix: Add explanatory comment to TypeScript directive
marshallswain Jul 16, 2025
711b3ad
feat: Complete TypeScript migration with Node 12+ compatibility
marshallswain Jul 16, 2025
e1bb0c9
fix: Downgrade rimraf to v3.0.2 for Node 12 compatibility
marshallswain Jul 16, 2025
0a9e99e
fix: Update package-lock.json for rimraf downgrade
marshallswain Jul 16, 2025
e45ad65
fix: Downgrade TypeScript to v4.9.5 for Node 12 compatibility
marshallswain Jul 16, 2025
42a75db
fix: Downgrade Sinon to v15.2.0 for Node 12 compatibility
marshallswain Jul 16, 2025
6d925ef
fix: Downgrade Sinon to v9.2.4 and increase Node heap size
marshallswain Jul 16, 2025
2904198
fix: Use multi-stage Docker build for Node 12 compatibility
marshallswain Jul 16, 2025
30e8065
fix: Update Node 12 CI to use Docker Compose with multi-stage build
marshallswain Jul 16, 2025
fdb8112
fix: Use 'docker compose' instead of 'docker-compose' in CI
marshallswain Jul 16, 2025
cd3db9e
fix: Remove platform-specific architecture from Docker files
marshallswain Jul 16, 2025
e3da6d7
fix: Add verification steps to Docker build process
marshallswain Jul 16, 2025
2b11300
fix: Copy source files selectively to avoid overwriting lib directory
marshallswain Jul 16, 2025
16e51ec
debug: Add working directory debugging to Docker build
marshallswain Jul 16, 2025
fcd01f5
fix: Simplify Docker build to ensure lib directory is preserved
marshallswain Jul 16, 2025
313a64b
fix: Simplify Node 12 testing by checking in pre-built lib files
marshallswain Jul 16, 2025
c0f6542
fix: Check in lib files for Node 12 compatibility testing
marshallswain Jul 16, 2025
371006b
feat: Add Node 12 compatibility testing with production dependencies
marshallswain Jul 16, 2025
f59ecd6
fix: Complete Node 12 compatibility testing with docker-compose
marshallswain Jul 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended'
],
plugins: ['@typescript-eslint'],
env: {
node: true,
es2020: true,
mocha: true
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'error',
'semi': ['error', 'always'],
'quotes': ['error', 'single'],
'no-trailing-spaces': 'error',
'eol-last': 'error'
},
ignorePatterns: ['lib/', 'node_modules/', 'types/']
};
20 changes: 20 additions & 0 deletions .github/workflows/node12.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Node 12 CI

on: [push, pull_request]

jobs:
test-node12:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run Node 12 tests with Docker Compose
run: |
# Build and run tests using docker compose
docker compose -f docker-compose.node12.yml up --build --abort-on-container-exit --exit-code-from app-node12

- name: Clean up Docker containers
if: always()
run: |
docker compose -f docker-compose.node12.yml down -v
23 changes: 15 additions & 8 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ jobs:

strategy:
matrix:
node-version: [12.x, 16.x]
node-version: [20.x, 22.x]
mongodb-version: [7.0]

steps:
- uses: actions/checkout@v2
- name: Start MongoDB
uses: supercharge/[email protected]
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Start MongoDB ${{ matrix.mongodb-version }}
uses: supercharge/[email protected]
with:
mongodb-version: 4.4
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-replica-set: test-rs
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
cache: 'npm'
- run: npm ci
- run: npm run lint && npm run build && npm run coverage
env:
CI: true
MONGODB_URI: mongodb://localhost:27017/feathers-mongoose-test?replicaSet=test-rs
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ node_modules
.lock-wscript

data/

# Compiled TypeScript output
# lib/ - temporarily checked in for Node 12 compatibility testing
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# Changelog

## [Unreleased](https://github.com/feathersjs-ecosystem/feathers-mongoose/tree/HEAD)
## [v9.0.0](https://github.com/feathersjs-ecosystem/feathers-mongoose/tree/v9.0.0) (2025-07-10)

[Full Changelog](https://github.com/feathersjs-ecosystem/feathers-mongoose/compare/v8.5.1...HEAD)
[Full Changelog](https://github.com/feathersjs-ecosystem/feathers-mongoose/compare/v8.5.1...v9.0.0)

**Breaking Changes:**

- Updated Node.js requirement to >= 18 (from >= 14)
- Updated to Feathers v5 dependencies (from v4)
- Added support for MongoDB versions 6, 7, and 8

**Enhancements:**

- Added support for Mongoose versions 6, 7, and 8
- Added support for both `rawResult` (Mongoose 7) and `includeResultMetadata` (Mongoose 8) options
- Updated GitHub Actions workflow to test against Node.js 18, 20, 22 and MongoDB 6, 7, 8
- Added Docker setup for testing with multiple versions of Node.js, MongoDB, and Mongoose
- Added test scripts for Mongoose 6, 7, and 8
- Improved compatibility with Apple Silicon (arm64) architecture

**Merged pull requests:**

Expand Down
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM --platform=linux/arm64 node:18-slim

WORKDIR /app

# Install build tools and system dependencies for native modules
RUN apt-get update && apt-get install -y \
build-essential \
python3 \
libkrb5-dev \
libgssapi-krb5-2 \
&& rm -rf /var/lib/apt/lists/*

# Copy package files first for better caching
COPY package*.json ./

# Install dependencies
RUN npm install --no-optional

# Copy the rest of the application
COPY . .

# Fix mocha permissions
RUN chmod +x node_modules/.bin/mocha

# Set environment variables
ENV NODE_ENV=test

# Command to run tests
CMD ["node", "node_modules/.bin/mocha", "--timeout", "15000", "--recursive", "test/", "--exit"]
36 changes: 36 additions & 0 deletions Dockerfile.node12
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use Node 12 for testing
FROM node:12-slim

WORKDIR /app

# Update sources to use archived repositories for older Debian versions
RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list \
&& echo "deb http://archive.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list \
&& apt-get update -o Acquire::Check-Valid-Until=false \
&& apt-get install -y \
build-essential \
python3 \
libkrb5-dev \
libgssapi-krb5-2 \
&& rm -rf /var/lib/apt/lists/*

# Copy package files first for better caching
COPY package*.json ./

# Install only runtime dependencies for Node 12 compatibility
RUN npm install --production --no-optional

# Install testing dependencies compatible with Node 12
RUN npm install [email protected] [email protected] --no-save --exact

# Copy the rest of the application (including pre-built lib files)
COPY . .

# Fix mocha permissions
RUN chmod +x node_modules/.bin/mocha

# Set environment variables
ENV NODE_ENV=test

# Command to run Node 12 compatible tests
CMD ["npm", "run", "test:node12"]
77 changes: 70 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# feathers-mongoose

[![CI](https://github.com/feathersjs-ecosystem/feathers-mongoose/workflows/CI/badge.svg)](https://github.com/feathersjs-ecosystem/feathers-mongoose/actions?query=workflow%3ACI)
[![Dependency Status](https://img.shields.io/david/feathersjs-ecosystem/feathers-mongoose.svg?style=flat-square)](https://david-dm.org/feathersjs-ecosystem/feathers-mongoose)
[![CI](https://github.com/feathersjs-ecosystem/feathers-mongoose/actions/workflows/nodejs.yml/badge.svg)](https://github.com/feathersjs-ecosystem/feathers-mongoose/actions/workflows/nodejs.yml)
[![npm version](https://img.shields.io/npm/v/feathers-mongoose.svg?style=flat-square)](https://www.npmjs.com/package/feathers-mongoose)
[![Download Status](https://img.shields.io/npm/dm/feathers-mongoose.svg?style=flat-square)](https://www.npmjs.com/package/feathers-mongoose)

A [Feathers](https://feathersjs.com) database adapter for [Mongoose](http://mongoosejs.com/), an object modeling tool for [MongoDB](https://www.mongodb.org/).
Expand All @@ -10,10 +10,33 @@ A [Feathers](https://feathersjs.com) database adapter for [Mongoose](http://mong
$ npm install --save mongoose feathers-mongoose
```

> **Note:** This adapter is currently tested against Mongoose 6. Mongoose 8 support is planned for a later date.

> __Important:__ `feathers-mongoose` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).

> This adapter also requires a [running MongoDB](https://docs.mongodb.com/getting-started/shell/#) database server.

### TypeScript Support

This adapter includes TypeScript definitions. When using TypeScript, you can import and use it as follows:

```typescript
import mongoose from 'mongoose';
import service from 'feathers-mongoose';

interface Message {
text: string;
createdAt: Date;
}

const Model = mongoose.model<Message>('Message', new mongoose.Schema({
text: { type: String, required: true },
createdAt: { type: Date, default: Date.now }
}));

app.use('/messages', service({ Model }));
```


## API

Expand Down Expand Up @@ -44,7 +67,7 @@ __Options:__
- `lean` (*optional*, default: `true`) - Runs queries faster by returning plain objects instead of Mongoose models.
- `id` (*optional*, default: `'_id'`) - The name of the id field property.
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size. When pagination is disabled (`paginate: false`), the adapter skips the total count query for better performance
- `whitelist` (*optional*) - A list of additional query parameters to allow (e..g `[ '$regex', '$populate' ]`)
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`)
- `overwrite` (*optional*, default: `true`) - Overwrite the document when update, making mongoose detect is new document and trigger default value for unspecified properties in mongoose schema.
Expand Down Expand Up @@ -87,6 +110,8 @@ The `mongoose` property is also useful for performing upserts on a `patch` reque

Using the `writeResult` mongoose option will return the write result of a `patch` operation, including the _ids of all upserted or modified documents. This can be helpful alongside the `upsert` flag, for detecting whether the outcome was a find or insert operation. More on write results is available in the [Mongo documentation](https://docs.mongodb.com/manual/reference/method/db.collection.update/#writeresult)

> **Performance Note:** When using `writeResult` with multi-document patch operations, the adapter uses an optimized path that performs the update directly without pre-fetching document IDs, resulting in better performance for write-only operations

```js
const data = { address: '123', identifier: 'my-identifier' }
const params = {
Expand Down Expand Up @@ -202,6 +227,12 @@ app.service('posts').find({
});
```

The `$populate` parameter supports various formats:
- String: `$populate: 'user'`
- Array of strings: `$populate: ['user', 'comments']`
- Object with options: `$populate: { path: 'user', select: 'name email' }`
- Array of objects: `$populate: [{ path: 'user' }, { path: 'comments', options: { limit: 5 } }]`

## Error handling

As of v7.3.0, the original Mongoose error can be retrieved on the server via:
Expand Down Expand Up @@ -398,16 +429,48 @@ This module is community maintained and open for pull requests. Features and bug
- Tests to reproduce the bug or test the feature
- Documentation updates (if necessary)

To contribute, fork and clone the repository. To run the tests, a MongoDB v4.0.0 server is required. If you do not have a MongoDB server running you can start one with:
To contribute, fork and clone the repository. This project uses Docker for local development to ensure consistency across different environments.

```
npm run mongodb
### Running Tests Locally

**Option 1: Using Docker (Recommended)**

The easiest way to run tests is using Docker Compose, which will set up MongoDB 7.0 with replica set configuration:

```bash
# Start MongoDB and run tests
docker-compose up --build

# Or run tests in watch mode
docker-compose up mongo # Start MongoDB in background
npm test # Run tests on host
```

The command needs to stay open while running the tests with
**Testing with Different Node Versions**

To test with Node 12 (minimum supported version), you can use the alternative Docker setup:

```bash
# Test with Node 12 (skips linting due to ESLint compatibility)
docker-compose -f docker-compose.node12.yml up --build
```

Note: Node 12 testing skips linting steps due to ESLint compatibility issues. A separate GitHub workflow handles Node 12 testing in CI.

**Option 2: Local MongoDB Setup**

If you prefer to use a local MongoDB installation, you'll need:
- MongoDB 7.0 or later
- Replica set configuration (required for transaction tests)

```bash
# Start MongoDB with replica set
mongod --replSet rs0

# Initialize replica set (first time only)
mongosh --eval "rs.initiate()"

# Run tests
npm test
```

Expand Down
43 changes: 43 additions & 0 deletions docker-compose.node12.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3.8'

services:
app-node12:
build:
context: .
dockerfile: Dockerfile.node12
volumes:
- .:/app:delegated
- node_modules_node12:/app/node_modules:delegated
environment:
- NODE_ENV=test
- MONGODB_URI=mongodb://mongo:27017/feathers-mongoose-test?replicaSet=rs0
depends_on:
mongo:
condition: service_healthy
networks:
- test-network
command: npm run test:node12

mongo:
image: mongo:7.0
ports:
- "27017:27017"
volumes:
- mongodb_data_node12:/data/db
networks:
- test-network
command: --bind_ip_all
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s

volumes:
node_modules_node12:
mongodb_data_node12:

networks:
test-network:
driver: bridge
Loading
Loading