@tomsd/mongodbclient

4.1.7 • Public • Published

@tomsd/mongodbclient

It's a handy mongodb client for easy-use.
See mongodbclient.netlify.app for details.

npm NPM

ci checks top language Maintenance depends on mongodb@6 depends on node greater or equal 18

Installation

npm install @tomsd/mongodbclient

Usage

import { MClient } from "@tomsd/mongodbclient";

const uri = "mongodb+srv://...";
const dbName = "mydb";
const collectionName = "mycollection";

const mdbc = new MClient(uri, dbName, collectionName);

const items = [
  { name: "alice" },
  { name: "bob" },
  { name: "charlie" },
  { name: "alice" }
];

(async () => {
  const { insertedCount } = await mdbc.insertMany(items);
  console.log(insertedCount); // 4

  const docs = await mdbc.read();
  console.log(docs);

  const { upsertedCount, modifiedCount } = await mdbc.upsert({
    ...docs[0],
    name: "david"
  });
  console.log(`upsertedCount: ${upsertedCount}, modifiedCount: ${modifiedCount}`);

  const names = await mdbc.distinct("name");
  console.log(`distinct names: ${names.length}`); // 4

  const itemLength = await mdbc.count();
  console.log(`count: ${itemLength}`); // 4

  const { deletedCount } = await mdbc.remove({});
  console.log(`deletedCount: ${deletedCount}`); // 4

})();

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.1.76latest

Version History

VersionDownloads (Last 7 Days)Published
4.1.76
4.1.64
4.1.52
4.1.41
4.1.32
4.1.20
4.1.10
4.1.02
4.0.42
4.0.31
4.0.20
4.0.10
4.0.01
3.0.1439
3.0.131
3.0.120
3.0.110
3.0.100
3.0.90
3.0.80
3.0.70
3.0.60
3.0.50
3.0.40
3.0.31
3.0.20
3.0.10
3.0.00
2.8.10
2.8.00
2.7.90
2.7.80
2.7.70
2.7.60
2.7.50
2.7.40
2.7.30
2.7.20
2.7.10
2.7.00
2.6.00
2.5.01
2.4.00
2.3.00
2.2.20
2.2.10
2.2.00
2.1.10
2.1.00
2.0.10
2.0.00
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i @tomsd/mongodbclient

Weekly Downloads

63

Version

4.1.7

License

MIT

Unpacked Size

15 kB

Total Files

6

Last publish

Collaborators

  • tomsd