applay-utils 1.8.20 → 1.8.23

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/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "applay-utils",
3
- "version": "1.8.20",
3
+ "version": "1.8.23",
4
4
  "description": "Utilitary tools for Applay applications",
5
5
  "scripts": {
6
- "postinstall": "node python-setup.js",
7
6
  "build": "npm version patch",
8
7
  "test": "echo \"Error: no test specified\" && exit 1"
9
8
  },
@@ -1,6 +1,7 @@
1
1
  # aggregate.py
2
2
  import sys, json
3
3
  from pymongo import MongoClient
4
+ from bson.json_util import dumps # <-- IMPORTANTE
4
5
 
5
6
  def main():
6
7
  data = json.loads(sys.stdin.read())
@@ -9,15 +10,20 @@ def main():
9
10
  db_name = data["db"]
10
11
  collection_name = data["collection"]
11
12
  pipeline = data["pipeline"]
12
- options = data.get("options", {})
13
13
 
14
14
  client = MongoClient(mongo_url, maxPoolSize=50)
15
15
  col = client[db_name][collection_name]
16
16
 
17
- cursor = col.aggregate(pipeline, { "allowDiskUse": True, **options })
17
+ cursor = col.aggregate(
18
+ pipeline,
19
+ allowDiskUse=True,
20
+ session=None
21
+ )
22
+
18
23
  result = list(cursor)
19
24
 
20
- print(json.dumps(result, ensure_ascii=False))
25
+ # dumps() serializa ObjectId, datetime, Binary, etc
26
+ print(dumps(result, ensure_ascii=False))
21
27
 
22
28
  if __name__ == "__main__":
23
29
  main()
@@ -4,16 +4,17 @@ const { spawn } = require("child_process");
4
4
  function aggregateAsync(db, collection, pipe, options = {}) {
5
5
  return new Promise((resolve, reject) => {
6
6
 
7
- const python = path.join(__dirname, ".python-env/bin/python");
8
- const script = path.join(__dirname, "aggregate.py");
7
+ const python = path.join(__dirname, "../.python-env/bin/python");
8
+ const script = path.join(__dirname, "../python-scripts/aggregate.py");
9
9
 
10
- const payload = JSON.stringify({
11
- mongoUrl: db.client.s.url,
10
+ const data = {
11
+ mongoUrl: db.databaseUrl,
12
12
  db: db.databaseName,
13
13
  collection,
14
- pipeline: pipe,
15
- options
16
- });
14
+ pipeline: pipe
15
+ }
16
+
17
+ const payload = JSON.stringify(data);
17
18
 
18
19
  const proc = spawn(python, [script]);
19
20