# ajv-bsontype-coerce

> coerces mongodb's bsonType validators

Latest version **1.0.6** (published 2018-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install ajv-bsontype-coerce
pnpm add ajv-bsontype-coerce
yarn add ajv-bsontype-coerce
bun add ajv-bsontype-coerce
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-08-19 |
| First published | 2018-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | BoLaMN |
| Maintainers | bolamn |

## Links

- npm: https://www.npmjs.com/package/ajv-bsontype-coerce
- Repository: https://github.com/BoLaMN/ajv-bsontype-coerce
- Homepage: https://github.com/BoLaMN/ajv-bsontype-coerce#readme
- Issues: https://github.com/BoLaMN/ajv-bsontype-coerce/issues
- npm.io page: https://npm.io/package/ajv-bsontype-coerce

## Dependencies (3)

- [bson](https://npm.io/package/bson.md) ^3.0.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [ajv-bsontype](https://npm.io/package/ajv-bsontype.md) ^1.0.4

## Recent versions

- 1.0.6 (latest) — 2018-08-19
- 1.0.5 — 2018-08-19
- 1.0.4 — 2018-08-19

## README

# ajv-bsontype-coerce

coerces mongodb's bsonType validators

* npm install ajv-bsontype-coerce --save

## Setup

```
var Ajv = require('ajv');
var ajv = new Ajv;
require('ajv-bsontype-coerce')(ajv);
```

### Usage

```
const schema = {
   required: [ "name", "year", "major", "gpa" ],
   properties: {
      name: {
         bsonType: "string",
         coerce: true,
         description: "must be a string and is required"
      },
      gender: {
         bsonType: "string",
         coerce: true,
         description: "must be a string and is not required"
      },
      year: {
         bsonType: "int",
         coerce: true,
         description: "must be an integer in [ 2017, 3017 ] and is required"
      },
      major: {
         enum: [ "Math", "English", "Computer Science", "History", null ],
         description: "can only be one of the enum values and is required"
      },
      gpa: {
         bsonType: [ "double" ],
         coerce: true,
         description: "must be a double and is required"
      }
   }
}

const data = {
   name: "Alice",
   year: 2019,
   major: "History",
   gpa: 3
}

ajv.validate(schema, data)
```

License: MIT

---
_Source: https://npm.io/package/ajv-bsontype-coerce · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
