@tomsd/mongodbclient 3.0.0 → 3.0.1

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 +37 -56
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -11,70 +11,51 @@ npm install @tomsd/mongodbclient
11
11
  import { MClient } from "@tomsd/mongodbclient";
12
12
 
13
13
  const uri = "mongodb+srv://...";
14
- const dbname = "mydb";
15
- const collectionname = "mycollection";
14
+ const dbName = "mydb";
15
+ const collectionName = "mycollection";
16
16
 
17
- const mdbc = new MClient(uri, dbname, collectionname);
17
+ const mdbc = new MClient(uri, dbName, collectionName);
18
18
 
19
- type Seed = {
20
- name: string;
21
- };
22
-
23
- type Entry = Seed & {
24
- _id: string;
25
- };
26
-
27
- const items: Seed[] = [
19
+ const items = [
28
20
  { name: "alice" },
29
21
  { name: "bob" },
30
22
  { name: "charlie" },
31
23
  { name: "alice" }
32
24
  ];
33
25
 
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);
26
+ (async () => {
27
+ const { insertedCount } = await mdbc.insertMany(items);
28
+ console.log(insertedCount); // 4
29
+
30
+ const collections = await mdbc.getCollections();
31
+ console.log(
32
+ collections.some(
33
+ // @ts-ignore
34
+ collection => collection.s.namespace.db === dbName
35
+ )
36
+ ); // true
37
+
38
+ const docs = await mdbc.read();
39
+ console.log(docs);
40
+
41
+ const { upsertedCount, modifiedCount } = await mdbc.upsert({
42
+ ...docs[0],
43
+ name: "david"
78
44
  });
45
+ console.log(`upsertedCount: ${upsertedCount}, modifiedCount: ${modifiedCount}`);
46
+
47
+ const names = await mdbc.distinct("name");
48
+ console.log(`distinct names: ${names.length}`); // 4
49
+
50
+ const { storageSize } = await mdbc.stats();
51
+ console.log(`storageSize: ${storageSize}`);
52
+
53
+ const itemLength = await mdbc.count();
54
+ console.log(`count: ${itemLength}`); // 4
55
+
56
+ const { deletedCount } = await mdbc.remove({});
57
+ console.log(`deletedCount: ${deletedCount}`); // 4
58
+
59
+ })();
79
60
 
80
61
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",