cgserver 8.9.0 → 8.9.2
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.
|
@@ -35,9 +35,6 @@ class MongoBaseService {
|
|
|
35
35
|
return rs.one;
|
|
36
36
|
}
|
|
37
37
|
async get(property, where) {
|
|
38
|
-
if (property) {
|
|
39
|
-
property = { projection: property };
|
|
40
|
-
}
|
|
41
38
|
let rs = await MongoManager_1.GMongoMgr.findOne(this._table, property, where);
|
|
42
39
|
return rs.one;
|
|
43
40
|
}
|
|
@@ -46,16 +43,10 @@ class MongoBaseService {
|
|
|
46
43
|
return rs.count;
|
|
47
44
|
}
|
|
48
45
|
async gets(property, where, sort, skip = 0, limit = 0) {
|
|
49
|
-
if (property) {
|
|
50
|
-
property = { projection: property };
|
|
51
|
-
}
|
|
52
46
|
let rs = await MongoManager_1.GMongoMgr.findMany(this._table, property, where, sort, skip, limit);
|
|
53
47
|
return rs.list;
|
|
54
48
|
}
|
|
55
49
|
async getRandoms(num, property, where) {
|
|
56
|
-
if (property) {
|
|
57
|
-
property = { projection: property };
|
|
58
|
-
}
|
|
59
50
|
let rs = await MongoManager_1.GMongoMgr.simpleAggregate(this._table, property, where, null, num);
|
|
60
51
|
return rs.list;
|
|
61
52
|
}
|
|
@@ -175,7 +175,7 @@ class MongoManager {
|
|
|
175
175
|
let list = [];
|
|
176
176
|
try {
|
|
177
177
|
let col = this._mongoDb.collection(collection);
|
|
178
|
-
let cursor = col.find(where, property);
|
|
178
|
+
let cursor = col.find(where, { projection: property });
|
|
179
179
|
if (sort) {
|
|
180
180
|
cursor = cursor.sort(sort);
|
|
181
181
|
}
|
|
@@ -393,7 +393,7 @@ class MongoManager {
|
|
|
393
393
|
rs.rs = i_rs;
|
|
394
394
|
return rs;
|
|
395
395
|
}
|
|
396
|
-
async simpleAggregate(collection, property
|
|
396
|
+
async simpleAggregate(collection, property, where, size, random_size) {
|
|
397
397
|
this._convertWhere(where);
|
|
398
398
|
let rs = { errcode: null, list: null };
|
|
399
399
|
if (!this._mongoDb) {
|
|
@@ -404,8 +404,12 @@ class MongoManager {
|
|
|
404
404
|
try {
|
|
405
405
|
let col = this._mongoDb.collection(collection);
|
|
406
406
|
let params = [];
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
if (where) {
|
|
408
|
+
params.push({ '$match': where });
|
|
409
|
+
}
|
|
410
|
+
if (property) {
|
|
411
|
+
params.push({ '$project': property });
|
|
412
|
+
}
|
|
409
413
|
if (random_size) {
|
|
410
414
|
params.push({ '$sample': { 'size': random_size } });
|
|
411
415
|
}
|