@ewb/mongoose-query 1.1.16 → 1.1.17

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/lib/QueryModel.js CHANGED
@@ -81,8 +81,7 @@ export class QueryModel {
81
81
  async updateMany(query, $in, body) {
82
82
  const $set = { ...body };
83
83
  if (this.options.updateDateKey) {
84
- $set[this.options.updateDateKey] =
85
- new Date();
84
+ $set[this.options.updateDateKey] = new Date();
86
85
  }
87
86
  return this._model.updateMany({ ...query, _id: { $in } }, { $set });
88
87
  }
@@ -162,8 +161,8 @@ export class QueryModel {
162
161
  const subDoc = await this._model.findOne({
163
162
  ...query.root,
164
163
  [sub]: { $elemMatch: subQuery },
165
- }, { [String(sub)]: 1 });
166
- return this.getSubDocument(sub, subDoc, subQuery._id);
164
+ }, { [`${String(sub)}.$`]: 1 });
165
+ return this.getSubDocument(sub, subDoc);
167
166
  }
168
167
  async subFindOneAndUpdate(sub, query, subQuery, body) {
169
168
  const $set = {};
@@ -199,14 +198,11 @@ export class QueryModel {
199
198
  return [];
200
199
  return docSub.populate.filter((x) => x[type] || x.onAll);
201
200
  }
202
- getSubDocument(key, doc, id) {
201
+ getSubDocument(key, doc) {
203
202
  if (!doc)
204
203
  return null;
205
204
  const array = doc[key];
206
205
  if (array && Array.isArray(array)) {
207
- if (id) {
208
- return (array.find((x) => x._id.equals(id)) || null);
209
- }
210
206
  return array[0] || null;
211
207
  }
212
208
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ewb/mongoose-query",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "type": "module",
5
5
  "description": "Parse queries and params to mongoose search. Strips dangerous keys and set corrects options with help of query values.",
6
6
  "main": "./lib/index.js",