Gathering detailed insights and metrics for moleculer-db-adapter-typeorm-mongo
Gathering detailed insights and metrics for moleculer-db-adapter-typeorm-mongo
Gathering detailed insights and metrics for moleculer-db-adapter-typeorm-mongo
Gathering detailed insights and metrics for moleculer-db-adapter-typeorm-mongo
npm install moleculer-db-adapter-typeorm-mongo
Typescript
Module System
Min. Node Version
Node Version
NPM Version
54.6
Supply Chain
93.2
Quality
72.1
Maintenance
25
Vulnerability
97.4
License
TypeScript (90.67%)
JavaScript (9.33%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
1,060
Last Day
1
Last Week
7
Last Month
25
Last Year
119
MIT License
13 Commits
1 Watchers
20 Branches
1 Contributors
Updated on Jun 13, 2020
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
600%
7
Compared to previous week
Last Month
92.3%
25
Compared to previous month
Last Year
-7%
119
Compared to previous year
2
28
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;
1$ npm install moleculer-db-adapter-typeorm-mongo --save
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
$ npm test
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.
find
Entity find
Property | Type | Default | Description |
---|---|---|---|
filters | Object | required | Filters object to apply |
1todo example
findOne
Entity fineone
Property | Type | Default | Description |
---|---|---|---|
query | Object | required | Query object |
1todo example
findById
Entity find by id
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
1todo example
findByIds
Entity find by array of ids
Property | Type | Default | Description |
---|---|---|---|
idList | `Array.<(Object | String)>` | required |
1todo example
count
Entity count
Property | Type | Default | Description |
---|---|---|---|
filters | Object | required | Object of filters to apply |
1todo example
insert
Entity insert
Property | Type | Default | Description |
---|---|---|---|
entity | Object | required | docuemnt to save |
1todo example
create
Entity create
Property | Type | Default | Description |
---|---|---|---|
entity | Object | required | document to create |
1todo example
insertMany
Entity insert array of objects
Property | Type | Default | Description |
---|---|---|---|
entities | Array.<Object> | required | Array of entities |
1todo example
updateMany
Entity update many
Property | Type | Default | Description |
---|---|---|---|
where | Promise | required | Promise Object filter |
update | Promise | required | Promise Object update deep partial |
1todo example
updateById
Entity update by id
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
update | Object | required | update object using deep partial |
1todo example
removeMany
Entity remove many
Property | Type | Default | Description |
---|---|---|---|
where | Promise | required | promise object filter |
1todo example
removeById
Entity remove by id
Property | Type | Default | Description |
---|---|---|---|
id | String | required | id of document |
1todo example
connect
Conect to database
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 |
Type: Connection
, Repository
, ConnectionManager
returns Connection, repository and connection manager
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
Property | Type | Default | Description |
---|---|---|---|
No input parameters. |
1this.disconnect(); // disconnects default service connection
createCursor
Create cursor
Property | Type | Default | Description |
---|---|---|---|
params | Object | required | |
isCounting | Boolean | false |
1todo example
addDBUser
Add user to database
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 |
1todo example
command
Run database command
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 |
1todo example
createDB
Create Database
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 |
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
Property | Type | Default | Description |
---|---|---|---|
url | any | required | Mongodb url wihtout database |
opts | any | required | Mongodb connection options |
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
Property | Type | Default | Description |
---|---|---|---|
obj | any | required | Database connection object |
userOpts | any | required | User object if user to be removed |
1todo example
updateDBUser
Update DB User
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) |
1todo example
The project is available under the MIT license.
Copyright (c) 2020 Karnith
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
54 existing vulnerabilities detected
Details
Score
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