@tomsd/mongodbclient 3.0.0 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +36 -56
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @tomsd/mongodbclient
2
2
 
3
+ ![npm](https://img.shields.io/npm/v/@tomsd/mongodbclient)
4
+ ![NPM](https://img.shields.io/npm/l/@tomsd/mongodbclient)
5
+ ![npms.io (quality)](https://img.shields.io/npms-io/quality-score/@tomsd/mongodbclient)
6
+ ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/@tomsd/mongodbclient)
7
+ ![Maintenance](https://img.shields.io/maintenance/yes/2022)
8
+ ![depends on mongodb@4](https://img.shields.io/badge/depends%20on-mongodb@4-informational)
9
+
3
10
  ## Installation
4
11
  ``` sh
5
12
  npm install @tomsd/mongodbclient
@@ -11,70 +18,43 @@ npm install @tomsd/mongodbclient
11
18
  import { MClient } from "@tomsd/mongodbclient";
12
19
 
13
20
  const uri = "mongodb+srv://...";
14
- const dbname = "mydb";
15
- const collectionname = "mycollection";
16
-
17
- const mdbc = new MClient(uri, dbname, collectionname);
18
-
19
- type Seed = {
20
- name: string;
21
- };
21
+ const dbName = "mydb";
22
+ const collectionName = "mycollection";
22
23
 
23
- type Entry = Seed & {
24
- _id: string;
25
- };
24
+ const mdbc = new MClient(uri, dbName, collectionName);
26
25
 
27
- const items: Seed[] = [
26
+ const items = [
28
27
  { name: "alice" },
29
28
  { name: "bob" },
30
29
  { name: "charlie" },
31
30
  { name: "alice" }
32
31
  ];
33
32
 
34
- mdbc.insertMany(items)
35
- .then((r: any) => {
36
- console.log(r.insertedCount); // 4
37
- return mdbc.getCollections();
38
- })
39
- .then((collections) => {
40
- console.log(
41
- collections.find(
42
- (collection: any) => collection.s.namespace.db === dbname
43
- )
44
- );
45
- return mdbc.read<Entry>();
46
- })
47
- .then((docs) => {
48
- console.log({
49
- docs,
50
- state: docs.length >= 4
51
- });
52
- return mdbc.upsert({
53
- _id:docs[0]._id,
54
- name:"david"
55
- });
56
- })
57
- .then((r: any) => {
58
- console.log(r.upsertedCount + r.modifiedCount);
59
- return mdbc.distinct("name", {});
60
- })
61
- .then((names) => {
62
- console.log(names);
63
- return mdbc.stats();
64
- })
65
- .then((r: any) => {
66
- console.log(r.storageSize);
67
- return mdbc.count({});
68
- })
69
- .then((n) => {
70
- console.log(n);
71
- return mdbc.remove({});
72
- })
73
- .then((r: any) => {
74
- console.log(r.deletedCount);
75
- })
76
- .catch((e) => {
77
- console.error(e);
33
+ (async () => {
34
+ const { insertedCount } = await mdbc.insertMany(items);
35
+ console.log(insertedCount); // 4
36
+
37
+ const docs = await mdbc.read();
38
+ console.log(docs);
39
+
40
+ const { upsertedCount, modifiedCount } = await mdbc.upsert({
41
+ ...docs[0],
42
+ name: "david"
78
43
  });
44
+ console.log(`upsertedCount: ${upsertedCount}, modifiedCount: ${modifiedCount}`);
45
+
46
+ const names = await mdbc.distinct("name");
47
+ console.log(`distinct names: ${names.length}`); // 4
48
+
49
+ const { storageSize } = await mdbc.stats();
50
+ console.log(`storageSize: ${storageSize}`);
51
+
52
+ const itemLength = await mdbc.count();
53
+ console.log(`count: ${itemLength}`); // 4
54
+
55
+ const { deletedCount } = await mdbc.remove({});
56
+ console.log(`deletedCount: ${deletedCount}`); // 4
57
+
58
+ })();
79
59
 
80
60
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "3.0.0",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",