# xlmongo

> ## 安装 ```js npm install xlmongo yarn add xlmongo ```

Latest version **0.2.5** (published 2021-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install xlmongo
pnpm add xlmongo
yarn add xlmongo
bun add xlmongo
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2021-07-19 |
| First published | 2020-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 31.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 2 |
| Author | junxi |
| Maintainers | ~xinlei3166 |
| Keywords | node, mongodb, pool |

## Links

- npm: https://www.npmjs.com/package/xlmongo
- Repository: https://github.com/xinlei3166/xlmongo
- Homepage: https://github.com/xinlei3166/xlmongo#readme
- Issues: https://github.com/xinlei3166/xlmongo/issues
- npm.io page: https://npm.io/package/xlmongo

## Dependencies (2)

- [mongodb](https://npm.io/package/mongodb.md) ^3.6.0
- [generic-pool](https://npm.io/package/generic-pool.md) ^3.7.1

## 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

- 0.2.5 (latest) — 2021-07-19
- 0.2.4 — 2021-07-19
- 0.2.3 — 2021-07-19
- 0.2.2 — 2020-08-10
- 0.2.1 — 2020-08-07
- 0.2.0 — 2020-08-07
- 0.1.4 — 2020-08-05
- 0.1.3 — 2020-08-03
- 0.1.2 — 2020-07-28
- 0.1.1 — 2020-07-27
- 0.1.0 — 2020-07-22

## README

# Mongodb连接池和SQL语句封装

## 安装
```js
npm install xlmongo
yarn add xlmongo
```

## 初始化
```js
const Mongo = require('xlmongo')

const m = new Mongo({
  host: 'localhost',
  port: '27017',
  db: 'ft',
  user: 'ft',
  password: '123456'
})
```

## 插入文档
```js
m.insertOne('pic', { name: '测试', url: '测试.png' }).then(res => {
  console.log(res)
})

m.insertMany('pic', [{ name: '测试1', url: '测试1.png' }, { name: '测试2', url: '测试2.png' }]).then(res => {
  console.log(res)

  m.pool.drain().then(function() { // 在应用程序中只调用一次, 关闭并停止使用此池。
    m.pool.clear()
  })
})
```

## 删除文档
```js
m.deleteOne('pic', {_id: '5f0d9ceefb161e6ff8e2bb1c'}).then(res => {
  console.log(res)
})

m.deleteMany('pic', {name: '测试2'}).then(res => {
  console.log(res)
})

m.find('pic', {name: '测试'}, {limit: 2}).then(r => {
  m.delete('pic', r.data).then(res => {
    console.log(res)
  })
})
```

## 更新文档
```js
m.updateOne('pic', {_id: '5f0eb289c6d7f27b8a498ed9', name: '测试'}, {$set:{name: '测试11111'}}).then(res => {
  console.log(res)
})

m.updateMany('pic', {name: '测试1'}, {$set:{name: '测试11111'}}).then(res => {
  console.log(res)
})

m.update('pic', [{oldData: {_id: '5f0eae133378f27ac488adcc', name: '测试1'}, newData: {$set:{name: '测试1111111111'}}},{oldData: {name: '测试2'}, newData: {$set:{name: '测试22222222'}}}]).then(res => {
  console.log(res)
})
```

## 查询文档
```js
m.findOne('pic', {_id: '5f0eb289c6d7f27b8a498ed9', name: '测试11111'}).then(res => {
  console.log(res)
})

m.find('pic', {name: '测试11111'}).then(res => {
  console.log(res)
})

m.find('pic', {name: '测试'}, {limit: 2}).then(res => {
  console.log(res)
})

m.find('pic', {name: '测试'}, { project: { _id: 0, name: 1}}).then(res => {
  console.log(res)
})

m.findOne('pic', {name: '测试'}, { projection: { _id: 0, name: 1}}).then(res => {
  console.log(res)
})
```

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