@mongoosejs/studio 0.1.17 → 0.1.18

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.
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const Archetype = require('archetype');
4
+ const authorize = require('../../authorize');
5
+
6
+ const GetCollectionInfoParams = new Archetype({
7
+ model: {
8
+ $type: 'string',
9
+ $required: true
10
+ },
11
+ roles: {
12
+ $type: ['string']
13
+ }
14
+ }).compile('GetCollectionInfoParams');
15
+
16
+ module.exports = ({ db }) => async function getCollectionInfo(params) {
17
+ const { model, roles } = new GetCollectionInfoParams(params);
18
+
19
+ await authorize('Model.getCollectionInfo', roles);
20
+
21
+ const Model = db.models[model];
22
+ if (Model == null) {
23
+ throw new Error(`Model ${model} not found`);
24
+ }
25
+
26
+ const [collectionOptions, stats] = await Promise.all([
27
+ Model.collection.options(),
28
+ Model.aggregate([
29
+ {
30
+ $collStats: {
31
+ storageStats: {},
32
+ count: {}
33
+ }
34
+ }
35
+ ]).then(res => res[0] ?? {})
36
+ ]);
37
+
38
+ return {
39
+ info: {
40
+ capped: !!stats.storageStats?.capped,
41
+ size: stats.storageStats?.size,
42
+ totalIndexSize: stats.storageStats?.totalIndexSize,
43
+ indexCount: stats.storageStats?.nindexes,
44
+ documentCount: stats.storageStats?.count,
45
+ hasCollation: !!collectionOptions?.collation,
46
+ collation: collectionOptions?.collation || null
47
+ }
48
+ };
49
+ };
@@ -9,6 +9,7 @@ exports.exportQueryResults = require('./exportQueryResults');
9
9
  exports.getDocument = require('./getDocument');
10
10
  exports.getDocuments = require('./getDocuments');
11
11
  exports.getDocumentsStream = require('./getDocumentsStream');
12
+ exports.getCollectionInfo = require('./getCollectionInfo');
12
13
  exports.getIndexes = require('./getIndexes');
13
14
  exports.listModels = require('./listModels');
14
15
  exports.updateDocument = require('./updateDocument');