Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@e22m4u/js-repository-mongodb-adapter

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@e22m4u/js-repository-mongodb-adapter

MongoDB adapter for @e22m4u/js-repository

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@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:

namedefault value
protocol'mongodb'
host'127.0.0.1'
port27017
database'database'
usernameundefined
passwordundefined

Example:

import {Schema} from '@e22m4u/js-repository';

const schema = new Schema();

// define datasource
schema.defineDatasource({
  name: 'myMongo', // datasource name
  adapter: 'mongodb', // adapter name
  // configuration
  host: '127.0.0.1',
  port: 27017,
  database: 'myDatabase',
});

// define model
schema.defineModel({
  name: 'user', // model name
  datasource: 'myMongo', // datasource name (see above)
  properties: { // model fields
    name: 'string',
    surname: 'string',
  },
});

// get repository by model name and create a record
const userRep = schema.getRepository('user');
const user = await userRep.create({name: 'John', surname: 'Doe'});

console.log(user);
// {
//   id: '64f3454e5e0893c13f9bf47e',
//   name: 'John',
//   surname: 'Doe',
// }

Testing

Start mongo:latest container using setup.sh script.

./setup.sh

Run tests

npm run test

License

MIT

Keywords

FAQs

Package last updated on 14 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc