# simple-db-model

> SimpleDBModel is a NodeJS library for manipulating MongoDB with Mongoose

Latest version **1.2.4** (published 2022-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-db-model
pnpm add simple-db-model
yarn add simple-db-model
bun add simple-db-model
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2022-01-17 |
| First published | 2021-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Monotter |
| Maintainers | monotter |
| Keywords | mongodb, mongoose, database, model, dbmodel, easydb, mongo, db, nosql, query, data, datastore, schema, model, document |

## Links

- npm: https://www.npmjs.com/package/simple-db-model
- Repository: https://github.com/monotter/simple-db-model
- Homepage: https://github.com/monotter/simple-db-model#readme
- Issues: https://github.com/monotter/simple-db-model/issues
- npm.io page: https://npm.io/package/simple-db-model

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.2.4 (latest) — 2022-01-17
- 1.2.3 — 2022-01-17
- 1.2.2 — 2022-01-17
- 1.2.1 — 2022-01-17
- 1.2.0 — 2022-01-17
- 1.1.5 — 2021-04-16
- 1.1.4 — 2021-04-16
- 1.1.3 — 2021-04-11
- 1.1.2 — 2021-04-11
- 1.1.1 — 2021-04-11
- 1.1.0 — 2021-04-11
- 1.0.5 — 2021-03-12
- 1.0.4 — 2021-03-03
- 1.0.3 — 2021-02-23
- 1.0.2 — 2021-02-19

## README

# SimpleDBModel
SimpleDBModel is a NodeJS library for manipulating MongoDB with Mongoose.

## Installation
Use the package manager [npm](https://www.npmjs.com/) to install SimpleDBModel.

```bash
npm install mongoose
npm install simple-db-model
```

## Overview and importing
```js
const DBModel = require("simple-db-model")
const mongo = require("mongoose")
//mongo.connect("mongodb://localhost/ExampleDatabase")
const PersonModel = new DBModel("Person", {
    Name: String,
    Surname: String,
    Age: Number
},mongo)
```
This part of code makes new Collection named `Person` with Name, Surname and Age properties at specified database on MongoDB.

## Examples

### Insert
```js
await PersonModel.insert({ Name: "Mert", Surname: "Çelik", Age: 18 })
```
This part of code inserts this data to `Person` collection and returns them.

### Select
```js
await PersonModel.select({ Age: 18 })
```
This part of code finds documents on `Person` collection which is `Age` property is `18` and returns them.

### Update
```js
await PersonModel.update({ Name: "Mert" }, { Surname: "CoolOne" })
```
This part of code finds documents on `Person` collection which is `Name` property is `Mert` and replaces their `Surname` property to `CoolOne`.

### Count
```js
await PersonModel.count({Surname: "CoolOne"})
```
This part of code finds documents on `Person` collection which is `Surname` property is `CoolOne` and returns count of them.

### Delete
```js
await PersonModel.delete({Age:{$gt:17}})
```
This part of code finds documents on `Person` collection which is `Age` property more than `17` and deletes them.

## Mesh Examples
### Defining Styles
```js
const scheme = {
    ExampleData1: String,
    ExampleData2: Number
}
const mongooseSchema = new mongoose.Schema(schema,{versionKey: false})
const mongooseModel = mongoose.model(CollectionName, mongooseSchema, CollectionName)

const ExampleModel = new DBModel("Person",mongooseSchema)
const ExampleModel = new DBModel(mongooseModel)
```
### Collections
```js
var collection = [
    { ExampleData1: "Hello", ExampleData2:100 },
    { ExampleData1: "Hello", ExampleData2:300 },
    { ExampleData1: "Hi", ExampleData2:300 }
]
await ExampleModel.insert(collection)
await ExampleModel.select(collection)
await ExampleModel.count(collection)
await ExampleModel.delete(collection)
```

### Single Operations
```js
await ExampleModel.select({ ExampleData1: "Hello", ExampleData2:100 }, { multiple: false })
await ExampleModel.update({ ExampleData1: "Hello", ExampleData2:100 }, { multiple: false })
await ExampleModel.delete({ ExampleData1: "Hello", ExampleData2:100 }, { multiple: false })
```

### Limit, Skip, Sort, Populate and Select
```js
await ExampleModel.select(undefined, { limit: 5 })
await ExampleModel.select(undefined, { skip: 2 })
await ExampleModel.select(undefined, { sort: { ExampleData2: "descending" }})
await ExampleModel.select(undefined, { select: [ "ExampleData1" ] })
await ExampleModel.select(undefined, { populate: "ObjectIDField" })

await ExampleModel.select(undefined, { limit: 5, skip: 2, populate:["ExampleData1", "ExampleData2"], sort: { ExampleData2: "descending" }, select: [ "ExampleData1" ] })
```

### Structure
```
[async] <Model>.select(<filter[object]|filters[array of objects]>, { multiple[default: true], limit, sort, skip, select, populate } = {})
[async] <Model>.insert(<property[object]|properties[array of objects]>)
[async] <Model>.update(<filter[object]>, <property[object]>, { multiple[default: true] } = {})
[async] <Model>.delete(<filter[object]|filters[array of objects]>, { multiple[default: true] } = {})
[async] <Model>.count(<filter[object]|filters[array of objects]>)
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License
[MIT](https://choosealicense.com/licenses/mit/)

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