@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

})();

Dependencies (2)

Dev Dependencies (16)

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