mongogems 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/savedPipeline.rb +39 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28de8703a8afa603455f269858c5c873846ec9f9b21fad898394d5aa35aa4e20
4
- data.tar.gz: 6cd512e3d237476bbb546980a1fa13a5b6bc14e28184d00a1e6d81963b8ef216
3
+ metadata.gz: 76e7dbd3e0694f3ad409e13c3530ed907a4d828281bec0f3f964e63cf3cc706c
4
+ data.tar.gz: c59ee55d845c14dac46e17d6dbcf0ba10b2242d9623839c94b212c92b9f7499a
5
5
  SHA512:
6
- metadata.gz: 7fd6977b2d1db41d6b06c06b11004fe36345aaede0bef449dda14f2d8ecf11565d3e038379db46efcd41b30034e030c92112ed043d659490aa23dd20ae53c4e7
7
- data.tar.gz: '0268cbe9853a5bb810d73aa7fcffb16fc0d6ce0b219b0982d84693404774bbd707b0775d76d23a71db93d9d24e7d36db98b5c710c77c624800f4cbf9d7ee9f3f'
6
+ metadata.gz: 941bf504d23cb010f8c21293c161788cb45d38e91e85aaaa3bd4dc2c9f5c70c9be0c240823c363889645d8f7d416af92dc380823706a6560a445bb2dc2458918
7
+ data.tar.gz: b9616a4cfd7458dc0bb1deb57b29c4dae8becff446fbef902fab8f00f60e4ce8eec616f70279c4393a9bc1c635b8a9e9fc862cb27a9ff825ca7416922824cd0e
data/lib/savedPipeline.rb CHANGED
@@ -32,9 +32,7 @@ def pipeline_to_mongosh_script(infile, outfile)
32
32
  mongosh_script_out =
33
33
  "//Query name: #{data['name']}
34
34
 
35
- use #{dbname};
36
-
37
- db.#{collname}.aggregate(
35
+ db.getSiblingDB('#{dbname}').#{collname}.aggregate(
38
36
  " + the_pipeline + "
39
37
  , {allowDiskUse: true}
40
38
  );
@@ -43,4 +41,42 @@ db.#{collname}.aggregate(
43
41
  File.write(outfile, mongosh_script_out)
44
42
  end
45
43
 
44
+
45
+ def pipeline_to_view_mongosh_script(infile, viewname, outfile)
46
+ txt = File.read(infile)
47
+ data = JSON.parse(txt)
48
+
49
+ ns_split = data['namespace'].split '.', 2
50
+ dbname = ns_split[0]
51
+ collname = ns_split[1]
52
+
53
+ the_pipeline = "[\n"
54
+ is_first = true
55
+ data['pipeline'].each do |pstage|
56
+ if not pstage["isEnabled"]
57
+ next
58
+ end
59
+
60
+ if is_first
61
+ is_first = false
62
+ else
63
+ the_pipeline += ', '
64
+ end
65
+ stage_txt = pstage['stage']
66
+ stage_txt = stage_txt.gsub("\\r", "\r").gsub("\\n", "\n")
67
+ the_pipeline += "{ #{pstage['stageOperator']}: " + stage_txt + " }"
68
+ end
69
+ the_pipeline += "\n]"
70
+
71
+ mongosh_script_out =
72
+ "//Query name: #{data['name']}
73
+
74
+ db.getSiblingDB('#{dbname}').createView('#{viewname}', '#{collname}',
75
+ " + the_pipeline + "
76
+ );
77
+ "
78
+
79
+ File.write(outfile, mongosh_script_out)
80
+ end
81
+
46
82
  # pipeline_to_mongosh_script filename, '/dev/null'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongogems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katkam Nitin Reddy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo