@kurai-io/mongo
Version:
Abstraction layer for Mongo database
75 lines (48 loc) • 1.72 kB
Markdown
Abstraction layer for Mongo database
```bash
npm install @kurai-io/mongo
yarn add @kurai-io/mongo
```
```typescript
// foundation.ts
import { mongo } from "@kurai-io/mongo"
const instance = mongo.createInstance("mongo://...")
const client = instance.createClient("db1")
// You can create clients even without instance
const client2 = mongo.createClient("mongo://", "db1")
```
```typescript
import { client, instance } from "./foundation.ts"
await client.connect()
// Or you can perform connection in a in-line manner
const inlineClient = await instance.createClient("db2").connect()
// Disconnect from current instance
client.disconnect()
```
```typescript
import { client, instance } from "./foundation.ts"
const col = client.collection<T>("myCollection") // => mongo Collection
// Now you can interact with "col" like
// with default mongo collection
```
You can copy and paste the MIT license summary from below.
```text
MIT License
Copyright (c) 2022 Kurai Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
```