Installations
npm install moleculer-db-adapter-typeorm-mongo
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 8.x.x
Node Version
14.8.0
NPM Version
6.14.8
Score
54.6
Supply Chain
93.2
Quality
72.1
Maintenance
25
Vulnerability
97.4
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (90.67%)
JavaScript (9.33%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
Karnith
Download Statistics
Total Downloads
1,060
Last Day
1
Last Week
7
Last Month
25
Last Year
119
GitHub Statistics
MIT License
13 Commits
1 Watchers
20 Branches
1 Contributors
Updated on Jun 13, 2020
Bundle Size
5.86 kB
Minified
1.95 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.5
Package Id
moleculer-db-adapter-typeorm-mongo@0.0.5
Unpacked Size
72.44 kB
Size
13.41 kB
File Count
8
NPM Version
6.14.8
Node Version
14.8.0
Oops! Something went wrong.
Peer Dependencies
2
Dev Dependencies
28
moleculer-db-adapter-typeorm-mongo 
MongoDB adapter for Moleculer DB service with typeorm. Still a work in progress but stable.
Essentially a clone and modification of the great work on adaptor for Sequelize by the author of the project and dkuida.
it covers only the basics - but when you need more than basics just use the exposed
1service.adapter.repository;
Features
- Standard and multi-tenancy database connecitons
- Create additional named typeorm connections in a service
- List databases from a connection
Install
1$ npm install moleculer-db-adapter-typeorm-mongo --save
Usage
1
2/**
3 * TypeORM db connection
4 */
5adapter: new TypeOrmDbAdapter({
6 database: serviceDB,
7 name: serviceName,
8 // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
9 // @ts-ignore
10 type: 'mongodb',
11 host: 'localhost',
12 port: 27017,
13 entities: [serviceEntity],
14 synchronize: true,
15 useNewUrlParser: true,
16 useUnifiedTopology: true,
17}),
18
19/**
20 * TypeORM db model
21 */
22model: Entity,
23
24/**
25 * Service db connection mode
26 * Either 'mt' for multitenant or 'stanard' for standard connection
27 * string is case insensative.
28 */
29mode: 'standard',
30
Todo
- gridfs integration for file / image storage in MongoDB
Test
$ npm test
Settings
Property | Type | Default | Description |
---|---|---|---|
No settings. |
Note:
idField
does not work with Sequelize adapter as you can freely set your own ID while creating the model.
Actions
Methods
find
Entity find
Parameters
Property | Type | Default | Description |
---|---|---|---|
filters | Object | required | Filters object to apply |
Examples
1todo example
findOne
Entity fineone
Parameters
Property | Type | Default | Description |
---|---|---|---|
query | Object | required | Query object |
Examples
1todo example
findById
Entity find by id
Parameters
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
Examples
1todo example
findByIds
Entity find by array of ids
Parameters
Property | Type | Default | Description |
---|---|---|---|
idList | `Array.<(Object | String)>` | required |
Examples
1todo example
count
Entity count
Parameters
Property | Type | Default | Description |
---|---|---|---|
filters | Object | required | Object of filters to apply |
Examples
1todo example
insert
Entity insert
Parameters
Property | Type | Default | Description |
---|---|---|---|
entity | Object | required | docuemnt to save |
Examples
1todo example
create
Entity create
Parameters
Property | Type | Default | Description |
---|---|---|---|
entity | Object | required | document to create |
Examples
1todo example
insertMany
Entity insert array of objects
Parameters
Property | Type | Default | Description |
---|---|---|---|
entities | Array.<Object> | required | Array of entities |
Examples
1todo example
updateMany
Entity update many
Parameters
Property | Type | Default | Description |
---|---|---|---|
where | Promise | required | Promise Object filter |
update | Promise | required | Promise Object update deep partial |
Examples
1todo example
updateById
Entity update by id
Parameters
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
update | Object | required | update object using deep partial |
Examples
1todo example
removeMany
Entity remove many
Parameters
Property | Type | Default | Description |
---|---|---|---|
where | Promise | required | promise object filter |
Examples
1todo example
removeById
Entity remove by id
Parameters
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
Examples
1todo example
connect
Conect to database
Parameters
Property | Type | Default | Description |
---|---|---|---|
mode | String | required | mode of adapter, either mt or standard |
options | Object | required | connection options |
cb | Object | required | callback with connection in mt mode |
Results
Type: Connection
, Repository
, ConnectionManager
returns Connection, repository and connection manager
Examples
1this.connect(); // connects to default db connection oof service // new connection object const newConnection = { database: 'products', type: String(process.env.DBENGINE), username: process.env.MONGOUSERNAME, password: process.env.MONGOPASSWORD, host: process.env.DBHOST, port: Number(process.env.DBPORT), authSource: process.env.AUTHSOURCE, appname: 'Cameo:service:testapiMT:Products', entities: [Products], synchronize: process.env.SYNCHRONIZE, useNewUrlParser: process.env.USENEWURLPARSER, useUnifiedTopology: process.env.USENEWURLPARSER, }; const productsConnection = await new this.Promise( async (resolve, reject) => { // pass connection type, connection object and callback to retrieve the new connection object already connected await this.connect('mt', newConnection, (conn) => { if (!conn) { return reject("can't create connection"); } // set new connection object to outside variable for use return resolve(conn); }); } ); // use new connection to query database await productsConnection.connection.connect(); console.log(await productsConnection.connection.getMongoRepository(Products).find()); // close connection when done await productsConnection.connection.close(); // use manager (Connection manager) to get all the available connections console.log(productsConnection.manager); // get connection you want to use const connection = productsConnection.manager.get('products') console.log(connection); // opens connection connection.connect(); {...} // closes connection connection.close();
disconnect
Disconnect from database
Parameters
Property | Type | Default | Description |
---|---|---|---|
No input parameters. |
Examples
1this.disconnect(); // disconnects default service connection
createCursor
Create cursor
Parameters
Property | Type | Default | Description |
---|---|---|---|
params | Object | required | |
isCounting | Boolean | false |
Examples
1todo example
addDBUser
Add user to database
Parameters
Property | Type | Default | Description |
---|---|---|---|
obj | any | required | Connection object |
obj.url | String | required | Database url |
obj.connectionOpts | Object | required | Database connection options |
obj.[key: | any | required | string] - Additional Key pair paramaters |
userOpts | any | required | User object |
userOpts.username | String | required | User name of user to be added |
userOpts.password | String | required | Password of user to be added |
userOpts.options | Object | required | Additional options to be passed to add user |
Examples
1todo example
command
Run database command
Parameters
Property | Type | Default | Description |
---|---|---|---|
url | String | required | Mongodb url |
connectionOpts | Object | required | Mongodb connection options |
command | Object | required | Command object to send |
options | Object | required | Additional options to add |
Examples
1todo example
createDB
Create Database
Parameters
Property | Type | Default | Description |
---|---|---|---|
obj | any | required | Connection object |
obj.url | String | required | Mongo db url |
obj.connectionOpts | Object | required | Mongo connection options |
obj.databaseName | String | required | Mongo db name |
userOpts | any | required | User object (optional) |
userOpts.username | String | required | User name |
userOpts.Password | String | required | User Password |
userOpts.options | Object | required | User options |
Examples
1await this.adapter.createDB( { url: `${process.env.URL}${tenantDB}?authSource=${process.env.AUTHSOURCE}`, connectionOpts: { useNewUrlParser: Boolean(process.env.USENEWURLPARSER), useUnifiedTopology: Boolean(process.env.USENEWURLPARSER), }, databaseName: tenantDB, }, { DBUser: ctx.params.db_username, DBPassword: ctx.params.db_password, options: { roles: ['dbOwner'] }, }, );
listDataBases
List Databases on server
Parameters
Property | Type | Default | Description |
---|---|---|---|
url | any | required | Mongodb url wihtout database |
opts | any | required | Mongodb connection options |
Examples
1console.log(
await this.adapter
.listDataBases(
`${process.env.URL}?authSource=${process.env.AUTHSOURCE}`,
{
useNewUrlParser: Boolean(process.env.USENEWURLPARSER),
useUnifiedTopology: Boolean(process.env.USENEWURLPARSER),
},
)
);
removeUser
Remove user from db
Parameters
Property | Type | Default | Description |
---|---|---|---|
obj | any | required | Database connection object |
userOpts | any | required | User object if user to be removed |
Examples
1todo example
updateDBUser
Update DB User
Parameters
Property | Type | Default | Description |
---|---|---|---|
obj | any | required | Connection object |
obj.url | String | required | Mongo db url |
obj.connectionOpts | Object | required | Mongo connection options |
userOpts | any | required | User object |
userOpts.username | String | required | User name |
userOpts.Password | String | required | User Password |
userOpts.options | Object | required | User options (roles) |
Examples
1todo example
License
The project is available under the MIT license.
Contact
Copyright (c) 2020 Karnith

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Reason
54 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-vfrc-7r7c-w9mx
- Warn: Project is vulnerable to: GHSA-7wwv-vh3v-89cq
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-6vfc-qv3f-vr6c
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-339j-hqgx-qrrx
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-29xr-v42j-r956
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-pf2j-9qmp-jqr2
- Warn: Project is vulnerable to: GHSA-fx4w-v43j-vc45
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
1.7
/10
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More