@e22m4u/js-repository-mongodb-adapter
English | Русский
MongoDB adapter for @e22m4u/js-repository
Installation
npm install @e22m4u/js-repository-mongodb-adapter
Configuration
All parameters are optional:
name | default value |
---|
protocol | 'mongodb' |
host | '127.0.0.1' |
port | 27017 |
database | 'database' |
username | undefined |
password | undefined |
Example:
import {Schema} from '@e22m4u/js-repository';
const schema = new Schema();
schema.defineDatasource({
name: 'myMongo',
adapter: 'mongodb',
host: '127.0.0.1',
port: 27017,
database: 'myDatabase',
});
schema.defineModel({
name: 'user',
datasource: 'myMongo',
properties: {
name: 'string',
surname: 'string',
},
});
const userRep = schema.getRepository('user');
const user = await userRep.create({name: 'John', surname: 'Doe'});
console.log(user);
Testing
Start mongo:latest
container using setup.sh
script.
./setup.sh
Run tests
npm run test
License
MIT