@ewb/mongoose-query 1.1.7 → 1.1.8
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/Query.js +5 -6
- package/lib/QueryModel.js +3 -4
- package/package.json +1 -1
package/lib/Query.js
CHANGED
|
@@ -37,16 +37,15 @@ export class Query {
|
|
|
37
37
|
return this._limit;
|
|
38
38
|
}
|
|
39
39
|
get root() {
|
|
40
|
+
const modelQuery = this._addToModelQuery[this._model];
|
|
40
41
|
const root = this._root;
|
|
41
|
-
if (this._model &&
|
|
42
|
+
if (this._model && modelQuery && Object.keys(modelQuery).length) {
|
|
42
43
|
if (root) {
|
|
43
|
-
return {
|
|
44
|
-
$and: [root, this._addToModelQuery[this._model]],
|
|
45
|
-
};
|
|
44
|
+
return { $and: [root, modelQuery] };
|
|
46
45
|
}
|
|
47
|
-
return
|
|
46
|
+
return { ...modelQuery };
|
|
48
47
|
}
|
|
49
|
-
return root;
|
|
48
|
+
return { ...root };
|
|
50
49
|
}
|
|
51
50
|
get model() {
|
|
52
51
|
return this._model;
|
package/lib/QueryModel.js
CHANGED
|
@@ -165,10 +165,9 @@ export class QueryModel {
|
|
|
165
165
|
for (const key in body) {
|
|
166
166
|
$set[`${String(sub)}.$.${key}`] = body[key];
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}, { $set });
|
|
168
|
+
const filter = query.root;
|
|
169
|
+
filter[sub] = { $elemMatch: subQuery };
|
|
170
|
+
await this._model.updateOne(filter, { $set });
|
|
172
171
|
return this.subFindOne(sub, query, subQuery);
|
|
173
172
|
}
|
|
174
173
|
async subDelete(sub, query, subQuery) {
|
package/package.json
CHANGED