@cocreate/mongodb 1.21.1 → 1.22.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.22.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.22.0...v1.22.1) (2025-04-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * webpack.config and devdependencies ([a3e4329](https://github.com/CoCreate-app/CoCreate-mongodb/commit/a3e4329af10c4532a52caf7dc8ee600fbe7b7950))
7
+
8
+ # [1.22.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.21.1...v1.22.0) (2024-12-19)
9
+
10
+
11
+ ### Features
12
+
13
+ * impoved projection handeling,mergeTtoDotNotation function for queries etc ([d18f84e](https://github.com/CoCreate-app/CoCreate-mongodb/commit/d18f84e82a9edced30aa42b13d9442e7c841b6e8))
14
+
1
15
  ## [1.21.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.21.0...v1.21.1) (2024-12-05)
2
16
 
3
17
 
package/docs/index.html CHANGED
@@ -1,228 +1,228 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <title>CoCreate-mongodb Documentation | CoCreateJS</title>
8
- <link
9
- rel="icon"
10
- type="image/png"
11
- sizes="32x32"
12
- href="https://cocreate.app/images/favicon.ico" />
13
- <meta
14
- name="description"
15
- content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
- <meta
17
- name="keywords"
18
- content="helper classes, utility classes, css framework, css library, inline style classes" />
19
- <meta name="robots" content="index,follow" />
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <title>CoCreate-mongodb Documentation | CoCreateJS</title>
8
+ <link
9
+ rel="icon"
10
+ type="image/png"
11
+ sizes="32x32"
12
+ href="https://cocreate.app/images/favicon.ico" />
13
+ <meta
14
+ name="description"
15
+ content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
+ <meta
17
+ name="keywords"
18
+ content="helper classes, utility classes, css framework, css library, inline style classes" />
19
+ <meta name="robots" content="index,follow" />
20
20
 
21
- <!-- CoCreate CSS CDN -->
22
- </head>
21
+ <!-- CoCreate CSS CDN -->
22
+ </head>
23
23
 
24
- <body>
25
- <div array="" object="" key="" id="cocreate-mongodb">
26
- <div
27
- class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
28
- <div class="display:flex align-items:center">
29
- <h2>CoCreate-mongodb</h2>
30
- </div>
31
- <div
32
- class="display:flex align-items:center font-size:20px"
33
- share-height="600"
34
- share-width="500"
35
- share-media="https://via.placeholder.com/300/09f/fff.png">
36
- <a
37
- href="https://github.com/CoCreate-app/CoCreate-mongodb"
38
- target="_blank"
39
- class="margin-right:15px"
40
- ><i class="fab fa-github"></i
41
- ></a>
42
- <a
43
- class="margin-right:15px share"
44
- share-network="twitter"
45
- title="Share on twitter"
46
- ><i class="fab fa-twitter"></i
47
- ></a>
48
- <a
49
- class="margin-right:15px share"
50
- share-network="facebook"
51
- title="Share on Facebook"
52
- ><i class="fab fa-facebook"></i
53
- ></a>
54
- <a
55
- class="margin-right:15px share"
56
- share-network="instagram"
57
- title="Share on instagram"
58
- ><i class="fab fa-instagram"></i
59
- ></a>
60
- <a
61
- class="margin-right:15px share"
62
- share-network="share"
63
- title="Share on share"
64
- ><i class="fas fa-share-alt"></i
65
- ></a>
66
- </div>
67
- </div>
68
- <h1 class="max-width:500px margin:20px_10px">
69
- A simple HTML5, CSS and pure javascript component. Easy
70
- configuration using data-attributes and highly styleable.
71
- </h1>
72
- <div id="mongodb-section" class="display:flex flex-wrap:wrap">
73
- <div class="flex-grow:1 width:300px padding:20px_10px">
74
- <h2
75
- class="border-bottom:1px_solid_lightgrey padding:5px_0px">
76
- Install
77
- </h2>
78
- <pre
79
- class="margin-top:15px"><code class="language-javascript">npm install cocreate-mongodb</code></pre>
80
- <p class="padding:10px_0px">Or you can use cdn link:</p>
81
- <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-mongodb.min.js</code></pre>
24
+ <body>
25
+ <div array="" object="" key="" id="cocreate-mongodb">
26
+ <div
27
+ class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
28
+ <div class="display:flex align-items:center">
29
+ <h2>CoCreate-mongodb</h2>
30
+ </div>
31
+ <div
32
+ class="display:flex align-items:center font-size:20px"
33
+ share-height="600"
34
+ share-width="500"
35
+ share-media="https://via.placeholder.com/300/09f/fff.png">
36
+ <a
37
+ href="https://github.com/CoCreate-app/CoCreate-mongodb"
38
+ target="_blank"
39
+ class="margin-right:15px"
40
+ ><i class="fab fa-github"></i
41
+ ></a>
42
+ <a
43
+ class="margin-right:15px share"
44
+ share-network="twitter"
45
+ title="Share on twitter"
46
+ ><i class="fab fa-twitter"></i
47
+ ></a>
48
+ <a
49
+ class="margin-right:15px share"
50
+ share-network="facebook"
51
+ title="Share on Facebook"
52
+ ><i class="fab fa-facebook"></i
53
+ ></a>
54
+ <a
55
+ class="margin-right:15px share"
56
+ share-network="instagram"
57
+ title="Share on instagram"
58
+ ><i class="fab fa-instagram"></i
59
+ ></a>
60
+ <a
61
+ class="margin-right:15px share"
62
+ share-network="share"
63
+ title="Share on share"
64
+ ><i class="fas fa-share-alt"></i
65
+ ></a>
66
+ </div>
67
+ </div>
68
+ <h1 class="max-width:500px margin:20px_10px">
69
+ A simple HTML5, CSS and pure javascript component. Easy
70
+ configuration using data-attributes and highly styleable.
71
+ </h1>
72
+ <div id="mongodb-section" class="display:flex flex-wrap:wrap">
73
+ <div class="flex-grow:1 width:300px padding:20px_10px">
74
+ <h2
75
+ class="border-bottom:1px_solid_lightgrey padding:5px_0px">
76
+ Install
77
+ </h2>
78
+ <pre
79
+ class="margin-top:15px"><code class="language-javascript">npm install cocreate-mongodb</code></pre>
80
+ <p class="padding:10px_0px">Or you can use cdn link:</p>
81
+ <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-mongodb.min.js</code></pre>
82
82
 
83
- <h2
84
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
85
- Usage
86
- </h2>
87
- <p class="padding:10px_0px">mongodb usage content</p>
88
- <pre><code class="language-html">&lt;div&gt;&lt;/div&gt;</code></pre>
83
+ <h2
84
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
85
+ Usage
86
+ </h2>
87
+ <p class="padding:10px_0px">mongodb usage content</p>
88
+ <pre><code class="language-html">&lt;div&gt;&lt;/div&gt;</code></pre>
89
89
 
90
- <h2
91
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
92
- Reference
93
- </h2>
94
- <p class="padding:10px_0px">
95
- This is mongodb reference content
96
- </p>
97
- <pre><code class="language-javascript">&lt;div&gt;&lt;/div&gt;</code></pre>
98
- <p class="padding:10px_0px">
99
- This is mongodb reference content
100
- </p>
90
+ <h2
91
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
92
+ Reference
93
+ </h2>
94
+ <p class="padding:10px_0px">
95
+ This is mongodb reference content
96
+ </p>
97
+ <pre><code class="language-javascript">&lt;div&gt;&lt;/div&gt;</code></pre>
98
+ <p class="padding:10px_0px">
99
+ This is mongodb reference content
100
+ </p>
101
101
 
102
- <h2
103
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
104
- Attributes
105
- </h2>
106
- <ul class="list-style-type:none">
107
- <li
108
- class="padding:15px_0px border-bottom:1px_solid_lightgrey">
109
- <h4>
110
- <span>mongodb</span>
111
- <span class="cocreate-badge success"
112
- >string</span
113
- >
114
- <span class="cocreate-badge warning"
115
- >optional</span
116
- >
117
- </h4>
118
- <p>mongodb-attribute</p>
119
- </li>
120
- <li
121
- class="padding:15px_0px border-bottom:1px_solid_lightgrey">
122
- <h4>
123
- <span>mongodb</span>
124
- <span class="cocreate-badge success"
125
- >string</span
126
- >
127
- <span class="cocreate-badge warning"
128
- >optional</span
129
- >
130
- </h4>
131
- <p>mongodb-attribute</p>
132
- </li>
133
- </ul>
134
- </div>
102
+ <h2
103
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
104
+ Attributes
105
+ </h2>
106
+ <ul class="list-style-type:none">
107
+ <li
108
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
109
+ <h4>
110
+ <span>mongodb</span>
111
+ <span class="cocreate-badge success"
112
+ >string</span
113
+ >
114
+ <span class="cocreate-badge warning"
115
+ >optional</span
116
+ >
117
+ </h4>
118
+ <p>mongodb-attribute</p>
119
+ </li>
120
+ <li
121
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
122
+ <h4>
123
+ <span>mongodb</span>
124
+ <span class="cocreate-badge success"
125
+ >string</span
126
+ >
127
+ <span class="cocreate-badge warning"
128
+ >optional</span
129
+ >
130
+ </h4>
131
+ <p>mongodb-attribute</p>
132
+ </li>
133
+ </ul>
134
+ </div>
135
135
 
136
- <div
137
- class="flex-grow:1 width:300px padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
138
- <!-- SandBox -->
139
- <h2
140
- class="border-bottom:1px_solid_lightgrey padding:5px_0px">
141
- Demo
142
- </h2>
143
- <div
144
- class="position:sticky top:0 padding:10px_0px height:100vh">
145
- <!-- SandBox -->
146
- <div
147
- class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
148
- id="playground">
149
- <div
150
- id="demo-code"
151
- resizable
152
- class="position:relative height:50%">
153
- <textarea
154
- type="code"
155
- lang="html"
156
- array="demos"
157
- object=""
158
- key="demo"
159
- save="false"
160
- id="demo"
161
- class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
162
- <div
163
- resize="bottom"
164
- class="background:lightgrey"></div>
165
- </div>
136
+ <div
137
+ class="flex-grow:1 width:300px padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
138
+ <!-- SandBox -->
139
+ <h2
140
+ class="border-bottom:1px_solid_lightgrey padding:5px_0px">
141
+ Demo
142
+ </h2>
143
+ <div
144
+ class="position:sticky top:0 padding:10px_0px height:100vh">
145
+ <!-- SandBox -->
146
+ <div
147
+ class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
148
+ id="playground">
149
+ <div
150
+ id="demo-code"
151
+ resizable
152
+ class="position:relative height:50%">
153
+ <textarea
154
+ type="code"
155
+ lang="html"
156
+ array="demos"
157
+ object=""
158
+ key="demo"
159
+ save="false"
160
+ id="demo"
161
+ class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
162
+ <div
163
+ resize="bottom"
164
+ class="background:lightgrey"></div>
165
+ </div>
166
166
 
167
- <div
168
- id="demo-preview"
169
- class="position:relative overflow:auto background-color:white">
170
- <div
171
- get-value="#demo"
172
- class="padding:20px"></div>
173
- </div>
167
+ <div
168
+ id="demo-preview"
169
+ class="position:relative overflow:auto background-color:white">
170
+ <div
171
+ get-value="#demo"
172
+ class="padding:20px"></div>
173
+ </div>
174
174
 
175
- <div
176
- class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
177
- <a
178
- class="margin-right:10px"
179
- id="eye"
180
- show="#eye-slash"
181
- hide="#eye, #demo-preview"
182
- toggle="code-height"
183
- toggle-selector="#demo-code"
184
- ><i class="far fa-eye"></i
185
- ></a>
186
- <a
187
- class="margin-right:10px"
188
- hidden
189
- id="eye-slash"
190
- show="#eye, #demo-preview"
191
- hide="#eye-slash"
192
- toggle="code-height"
193
- toggle-selector="#demo-code"
194
- ><i class="fas fa-eye-slash"></i
195
- ></a>
196
- <a
197
- class="margin-right:10px"
198
- id="code"
199
- show="#code-slash"
200
- hide="#code, #demo-code"
201
- ><i class="fa fa-code"></i
202
- ></a>
203
- <a
204
- class="margin-right:10px"
205
- hidden
206
- id="code-slash"
207
- show="#code, #demo-code"
208
- hide="#code-slash"
209
- ><i class="fas fa-code"></i
210
- ></a>
211
- <a
212
- class="margin-right:5px"
213
- fullscreen
214
- target="#playground"
215
- ><i class="fas fa-expand"></i
216
- ></a>
217
- </div>
218
- </div>
219
- <!-- End SandBox -->
220
- </div>
221
- </div>
222
- </div>
223
- </div>
175
+ <div
176
+ class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
177
+ <a
178
+ class="margin-right:10px"
179
+ id="eye"
180
+ show="#eye-slash"
181
+ hide="#eye, #demo-preview"
182
+ toggle="code-height"
183
+ toggle-query="#demo-code"
184
+ ><i class="far fa-eye"></i
185
+ ></a>
186
+ <a
187
+ class="margin-right:10px"
188
+ hidden
189
+ id="eye-slash"
190
+ show="#eye, #demo-preview"
191
+ hide="#eye-slash"
192
+ toggle="code-height"
193
+ toggle-query="#demo-code"
194
+ ><i class="fas fa-eye-slash"></i
195
+ ></a>
196
+ <a
197
+ class="margin-right:10px"
198
+ id="code"
199
+ show="#code-slash"
200
+ hide="#code, #demo-code"
201
+ ><i class="fa fa-code"></i
202
+ ></a>
203
+ <a
204
+ class="margin-right:10px"
205
+ hidden
206
+ id="code-slash"
207
+ show="#code, #demo-code"
208
+ hide="#code-slash"
209
+ ><i class="fas fa-code"></i
210
+ ></a>
211
+ <a
212
+ class="margin-right:5px"
213
+ fullscreen
214
+ target="#playground"
215
+ ><i class="fas fa-expand"></i
216
+ ></a>
217
+ </div>
218
+ </div>
219
+ <!-- End SandBox -->
220
+ </div>
221
+ </div>
222
+ </div>
223
+ </div>
224
224
 
225
- <!--CoCreateJS-->
226
- <script src="https://CoCreate.app/dist/CoCreate.js"></script>
227
- </body>
225
+ <!--CoCreateJS-->
226
+ <script src="https://CoCreate.app/dist/CoCreate.js"></script>
227
+ </body>
228
228
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.21.1",
3
+ "version": "1.22.1",
4
4
  "description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "mongodb",
package/src/index.js CHANGED
@@ -375,8 +375,8 @@ function object(method, data) {
375
375
  options = {};
376
376
 
377
377
  if (data.$filter && data.$filter.key)
378
- projection = data.$filter.key
379
-
378
+ projection = data.$filter.key;
379
+
380
380
  if (method === "update")
381
381
  createUpdate(update, options, data, true);
382
382
 
@@ -493,10 +493,9 @@ function object(method, data) {
493
493
  result.insertedId.toString();
494
494
  // documents.push({ ...data[type][i], ...reference })
495
495
  } else if (method === "read") {
496
- result = await arrayObj.findOne(
497
- query,
498
- {projection}
499
- );
496
+ result = await arrayObj.findOne(query, {
497
+ projection
498
+ });
500
499
  if (result)
501
500
  result._id = result._id.toString();
502
501
 
@@ -548,13 +547,16 @@ function object(method, data) {
548
547
  continue;
549
548
  }
550
549
  } else if (method === "update") {
551
- if (update['$pull'] && update['$unset']) {
550
+ if (
551
+ update["$pull"] &&
552
+ update["$unset"]
553
+ ) {
552
554
  result = await arrayObj.updateOne(
553
555
  query,
554
- {$unset: update['$unset']},
556
+ { $unset: update["$unset"] },
555
557
  options
556
558
  );
557
- delete update['$unset']
559
+ delete update["$unset"];
558
560
  }
559
561
  result = await arrayObj.updateOne(
560
562
  query,
@@ -611,14 +613,14 @@ function object(method, data) {
611
613
  document = "";
612
614
  if (Object.keys(sort).length > 0)
613
615
  cursor = arrayObj
614
- .find(query, {projection})
616
+ .find(query, { projection })
615
617
  .sort(sort)
616
618
  .skip(index)
617
619
  .limit(limit)
618
620
  .allowDiskUse(true);
619
621
  else
620
622
  cursor = arrayObj
621
- .find(query, {projection})
623
+ .find(query, { projection })
622
624
  .sort(sort)
623
625
  .skip(index)
624
626
  .limit(limit);
@@ -718,15 +720,23 @@ function object(method, data) {
718
720
 
719
721
  let result;
720
722
  if (method === "update") {
721
- if (update['$pull'] && update['$unset']) {
722
- result = await arrayObj.updateOne(
723
- {
724
- _id: document._id
725
- },
726
- {$unset: update['$unset']},
727
- options
728
- );
729
- delete update['$unset']
723
+ if (
724
+ update["$pull"] &&
725
+ update["$unset"]
726
+ ) {
727
+ result =
728
+ await arrayObj.updateOne(
729
+ {
730
+ _id: document._id
731
+ },
732
+ {
733
+ $unset: update[
734
+ "$unset"
735
+ ]
736
+ },
737
+ options
738
+ );
739
+ delete update["$unset"];
730
740
  }
731
741
 
732
742
  if (options.returnNewDocument) {
@@ -915,13 +925,13 @@ function createUpdate(update, options, data, isGlobal) {
915
925
  operator = "$unset";
916
926
  updates[key] = 1;
917
927
  // if (!updates["$pull"]) updates["$pull"] = {};
918
- const pullkey = key.split('.');
919
- pullkey.shift();
920
- pullkey.pop();
928
+ const pullkey = key.split(".");
929
+ pullkey.shift();
930
+ pullkey.pop();
921
931
  // updates["$pull"][pullkey.join('.')] = null;
922
932
  // updates["$pull"][pullkey.join('.')] = { $in: [null] };
923
- if (!update["$pull"]) update["$pull"] = {};
924
- update["$pull"][pullkey.join('.')] = null;
933
+ if (!update["$pull"]) update["$pull"] = {};
934
+ update["$pull"][pullkey.join(".")] = null;
925
935
  } else if (operator === "$pop") {
926
936
  key = arrayKey;
927
937
  updates[key] = index || 1;
@@ -980,41 +990,45 @@ async function createFilter(data, arrayObj) {
980
990
  return value;
981
991
  }
982
992
 
993
+ // Recursive function to merge keys into dot notation
994
+ function mergeToDotNotation(obj, parentKey = "", result = {}) {
995
+ for (let key in obj) {
996
+ const isOperator = key.startsWith("$");
997
+ const currentKey = parentKey ? `${parentKey}.${key}` : key;
998
+
999
+ if (
1000
+ obj[key] &&
1001
+ typeof obj[key] === "object" &&
1002
+ !Array.isArray(obj[key])
1003
+ ) {
1004
+ if (isOperator) {
1005
+ // Ensure operators are grouped under their parent key
1006
+ result[parentKey] = result[parentKey] || {};
1007
+ result[parentKey][key] = obj[key];
1008
+ } else {
1009
+ // Recurse into nested objects
1010
+ mergeToDotNotation(obj[key], currentKey, result);
1011
+ }
1012
+ } else {
1013
+ // Assign to result, merging into dot notation if applicable
1014
+ if (isOperator) {
1015
+ result[parentKey] = result[parentKey] || {};
1016
+ result[parentKey][key] = obj[key];
1017
+ } else {
1018
+ result[currentKey] = obj[key];
1019
+ }
1020
+ }
1021
+ }
1022
+ return result;
1023
+ }
1024
+
983
1025
  if (data.$filter.query) {
984
1026
  for (let key in data.$filter.query) {
985
1027
  if (Array.isArray(data.$filter.query[key])) {
986
1028
  // Handle $or operator with an array of conditions
987
1029
  query[key] = data.$filter.query[key].map((condition) => {
988
1030
  let newCondition = {};
989
- for (let subKey in condition) {
990
- if (
991
- typeof condition[subKey] === "object" &&
992
- condition[subKey] !== null
993
- ) {
994
- newCondition[subKey] = {};
995
- for (let subCondition in condition[subKey]) {
996
- if (subKey == "_id")
997
- newCondition[subKey][subCondition] =
998
- ObjectId(
999
- condition[subKey][subCondition]
1000
- );
1001
- else
1002
- newCondition[subKey][subCondition] =
1003
- convertIfDate(
1004
- condition[subKey][subCondition]
1005
- );
1006
- }
1007
- } else {
1008
- if (subKey == "_id")
1009
- newCondition[subKey] = ObjectId(
1010
- condition[subKey]
1011
- );
1012
- else
1013
- newCondition[subKey] = convertIfDate(
1014
- condition[subKey]
1015
- );
1016
- }
1017
- }
1031
+ mergeToDotNotation(condition, "", newCondition);
1018
1032
  return newCondition;
1019
1033
  });
1020
1034
  } else if (
@@ -1022,22 +1036,13 @@ async function createFilter(data, arrayObj) {
1022
1036
  data.$filter.query[key] !== null
1023
1037
  ) {
1024
1038
  // Handle general object conditions
1025
- query[key] = {};
1026
- for (let condition in data.$filter.query[key]) {
1027
- if (key == "_id")
1028
- query[key][condition] = ObjectId(
1029
- data.$filter.query[key][condition]
1030
- );
1031
- else
1032
- query[key][condition] = convertIfDate(
1033
- data.$filter.query[key][condition]
1034
- );
1035
- }
1039
+ mergeToDotNotation(data.$filter.query[key], key, query);
1036
1040
  } else {
1037
1041
  // Handle direct values
1038
- if (key == "_id")
1039
- query[key] = ObjectId(data.$filter.query[key]);
1040
- else query[key] = convertIfDate(data.$filter.query[key]);
1042
+ query[key] =
1043
+ key === "_id"
1044
+ ? ObjectId(data.$filter.query[key])
1045
+ : convertIfDate(data.$filter.query[key]);
1041
1046
  }
1042
1047
  }
1043
1048
  }
@@ -1045,8 +1050,7 @@ async function createFilter(data, arrayObj) {
1045
1050
  if (data.$filter.sort) {
1046
1051
  for (let i = 0; i < data.$filter.sort.length; i++) {
1047
1052
  let direction = data.$filter.sort[i].direction;
1048
- if (direction == "desc" || direction == -1) direction = -1;
1049
- else direction = 1;
1053
+ direction = direction === "desc" || direction === -1 ? -1 : 1;
1050
1054
 
1051
1055
  sort[data.$filter.sort[i].key] = direction;
1052
1056
  }
@@ -1077,7 +1081,10 @@ function parseRegExp(regExpString) {
1077
1081
 
1078
1082
  function createProjection(projection, data) {
1079
1083
  Object.keys(data).forEach((key) => {
1080
- if (!["_id", "organization_id", "isFIlter"].includes(key) && !key.startsWith("$"))
1084
+ if (
1085
+ !["_id", "organization_id", "isFIlter"].includes(key) &&
1086
+ !key.startsWith("$")
1087
+ )
1081
1088
  projection[key.replace(/\[(\d+)\]/g, ".$1")] = 1;
1082
1089
  });
1083
1090