Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@caruuto/api-mongodb
Advanced tools
To use this adapter with your API installation, you'll need to add it to your API's dependencies:
$ cd my-api
$ npm install @caruuto/api-mongodb
To run the test suite you'll need a MongoDB server running on localhost with the default port of 27017. If you've changed the default port, modify the test configuration file at config/mongodb.test.json
. This file is created from config/mongodb.test.json.sample
the first time the test suite is run.
Run the tests:
$ git clone https://github.com/caruuto/api-mongodb.git
$ cd api-mongodb
$ npm test
Configuration settings are defined in JSON files within a /config
directory at the root of your API application. API uses a configuration file for the MongoDB connector that matches the environment you are running under.
The naming convention for MongoDB configuration files follows the format mongodb.<environment>.json
Assuming that the entry point for your application is main.js
and launching it with the following command, API will attempt to load a MongoDB configuration file named mongodb.production.js
.
$ NODE_ENV=production node main.js
my-api/
config/ # contains environment-specific configuration properties
config.development.json # main API configuration file, development environment
config.production.json
mongodb.development.json # MongoDB configuration file, development environment
mongodb.production.json
main.js # the entry point of the app
package.json
workspace/
collections/ # collection schema files
endpoints/ # custom Javascript endpoints
Specifies the MongoDB database(s) to connect to.
{
"enableCollectionDatabases": false,
"databases": [
{
"id": "authdb",
"hosts": "127.0.0.1:27017",
"username": "johndoe",
"password": "topsecret"
},
{
"default": true,
"id": "secondary",
"hosts": "127.0.0.1:27018"
}
]
}
enableCollectionDatabases
Determines whether the database portion of the URL should dictate the actual MongoDB database to be used. When enabled, the request GET /1.0/mydatabase/mycollection
would look for documents in a database with the ID mydatabase
. If disabled, the default database (i.e. containing the property default: true
in the configuration file) will be used.
databases
The list of MongoDB databases to be used, as an array. Each database must be defined as an object with the following properties:
authDatabase
The database to authenticate against when supplying a username and password.
''
DB_{database}_AUTH_SOURCE
authMechanism
If no authentication mechanism is specified or the mechanism DEFAULT is specified, the driver will attempt to authenticate using the SCRAM-SHA-1 authentication method if it is available on the MongoDB server. If the server does not support SCRAM-SHA-1 the driver will authenticate using MONGODB-CR.
''
DB_{database}_AUTH_MECHANISM
default
Whether this database should be used as the default (main) database. When no database has the default
flag, the first one in the array will be used as default.
false
DB_{database}_DEFAULT
hosts
Comma-separated string of MongoDB hosts, including port (e.g. localhost,localhost:27018,localhost:27019).
DB_{database}_HOSTS
id
Database unique identifier.
maxPoolSize
The maximum number of connections in the connection pool.
0
DB_{database}_MAX_POOL
password
The access password, if one is needed.
""
DB_{database}_PASSWORD
readPreference
How MongoDB routes read operations to the members of a replica set - see https://docs.mongodb.com/manual/reference/read-preference/.
"primary"
, "primaryPreferred"
, "secondary"
, "secondaryPreferred"
or "nearest"
"secondaryPreferred"
replicaSet
The name of the replica set to identify the hosts.
ssl
Whether to initiate the connection with TLS/SSL.
false
username
The access username, if one is needed.
""
DB_{database}_USERNAME
FAQs
A MongoDB adapter for an API
The npm package @caruuto/api-mongodb receives a total of 0 weekly downloads. As such, @caruuto/api-mongodb popularity was classified as not popular.
We found that @caruuto/api-mongodb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.