@tomsd/mongodbclient
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

@tomsd/mongodbclient

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

npm NPM npms.io (quality) Libraries.io dependency status for latest release Maintenance depends on mongodb@6

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.0.020latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.020
3.0.140
3.0.130
3.0.120
3.0.110
3.0.100
3.0.90
3.0.80
3.0.70
3.0.60
3.0.51
3.0.40
3.0.30
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.00
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

21

Version

4.0.0

License

MIT

Unpacked Size

20.2 kB

Total Files

6

Last publish

Collaborators

  • tomsd