mongogems 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc20b0788d795db12040358deb32ed77388f13fb22ede8ed9d324176de5baabb
4
- data.tar.gz: bd7984187737c6940c356527329c542236c6a284d712a29229c005121022ad45
3
+ metadata.gz: e639c23eb9a584d08e120ea876bcdeeb9df0ac92ee229d40a86edde6efd8e0a8
4
+ data.tar.gz: 20d5eda11c6d4d8cc21e60ab7d28f27b25d81a1feca0d8ff07fda85c2b9af02f
5
5
  SHA512:
6
- metadata.gz: fe38bbb5cc95e7fe2fba6e7c98a2e46f9ed340f97b77aed9102c2cf1b5d3d1626002a47053b927a8bb59ffd20ccc0dd1ad7d30493a6c8a0f38c7d4769983f80a
7
- data.tar.gz: 785812a50bbe55a40ad81c462a1a618981c1ff9196871176d36696f419e942e2440fdd6ead609c41517cda5e7648e7ea10d73bfbf1be8f3a306b7c45ca245d0a
6
+ metadata.gz: d73f83bf2fc439efa326d609c8a1f68370372ef5d4a10f03aa920481db6057dd84b7578faa4ded4b98c4e585092b43336dfc7546ce70efd6b7023c457f8e66c6
7
+ data.tar.gz: 363ad86fecedf6bb90d4d2d2aae9c0d3d1e82269500dcc78daee2520d69edb4d317208db4fbebb9821d6c01cec4c2101ce50bd156cc855a313d25439d59cb97a
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require_relative '../lib/indexes'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage: mongoindex2file [options]'
9
+
10
+ opts.on('-o', '--output=OUTFILE', 'Output file to write to') do |val|
11
+ options[:output] = val
12
+ end
13
+
14
+ opts.on('-uri', '--uri=URI', 'URI to MongoDB') do |val|
15
+ options[:uri] = val
16
+ end
17
+
18
+ opts.on('-d', '--database=DB', '(optional) Database to fetch indexes from') do |val|
19
+ options[:db] = val
20
+ end
21
+
22
+ opts.on('-c', '--collection=COLL', '(optional) Collection to fetch indexes from') do |val|
23
+ options[:coll] = val
24
+ end
25
+
26
+ opts.on('-h', '--help', 'Help') do |val|
27
+ puts opts
28
+ exit
29
+ end
30
+ end.parse!
31
+
32
+ if options[:output].nil?
33
+ puts 'Missing arguments. Execute with -h for help'
34
+ exit
35
+ end
36
+
37
+ get_indexes_script options[:uri], options[:db], options[:coll], options[:output]
data/bin/mongolog2file ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require_relative '../lib/logs'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage: mongolog2file [options]'
9
+
10
+ opts.on('-o', '--output=OUTFILE', 'Output file to write to') do |val|
11
+ options[:output] = val
12
+ end
13
+
14
+ opts.on('-uri', '--uri=URI', 'URI to MongoDB') do |val|
15
+ options[:uri] = val
16
+ end
17
+
18
+ opts.on('-h', '--help', 'Help') do |val|
19
+ puts opts
20
+ exit
21
+ end
22
+ end.parse!
23
+
24
+ if options[:output].nil?
25
+ puts 'Missing arguments. Execute with -h for help'
26
+ exit
27
+ end
28
+
29
+ get_logs options[:uri], options[:output]
30
+
data/lib/indexes.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'mongo'
2
+ require 'json'
3
+
4
+ def get_indexes_script(uri, db_name=nil, coll_name=nil, outfile)
5
+ client = Mongo::Client.new(uri)
6
+
7
+
8
+ db_list = []
9
+ if not db_name.nil?
10
+ db_list.push db_name
11
+ else
12
+ client.use('admin').command(listDatabases: 1).first['databases'].each do |iter| # read the name property
13
+ iter_db_name = iter['name']
14
+ db_list.push iter_db_name
15
+ end
16
+ end
17
+
18
+ # client = client.use 'test'
19
+
20
+ # cur = client.command listCollections: 1
21
+ # rset = cur.to_a
22
+ # rset = rset.first['cursor']['firstBatch']
23
+ # rset
24
+
25
+ scripts = []
26
+
27
+ db_list.each do |iter_db|
28
+ client = client.use iter_db
29
+ scripts.push "use #{iter_db};"
30
+ if coll_name.nil?
31
+ colls = client.collections
32
+ else
33
+ colls = [coll_name]
34
+ end
35
+
36
+ colls.each do |coll|
37
+ coll.indexes.each do |idx|
38
+ txt = gen_idx_script idx, coll.name
39
+ scripts.push txt
40
+ end
41
+ end
42
+ end
43
+
44
+ txtscripts = scripts.join "\r\n"
45
+
46
+ File.open outfile, 'w' do |f|
47
+ f.write txtscripts
48
+ end
49
+ end
50
+
51
+ def gen_idx_script(idIndex, collname)
52
+ idx_name = idIndex['name']
53
+ idx_spec = JSON.dump(idIndex['key'])
54
+ idx_options = {}
55
+ idIndex.each do |k, v|
56
+ if ['v', 'key'].include? k then
57
+ next
58
+ end
59
+ idx_options[k] = v
60
+ end
61
+ opt_spec = JSON.dump idx_options
62
+ txt = "db.#{collname}.createIndex(#{idx_spec}, #{opt_spec});"
63
+ end
64
+
65
+ # script = (get_indexes_script 'mongodb://localhost').join "\n"
66
+ # puts script
data/lib/logs.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'mongo'
2
+ require 'json'
3
+
4
+ def get_logs(uri, filename)
5
+ client = Mongo::Client.new(uri)
6
+ cur = client.command getLog: 'global'
7
+ rset = cur.to_a
8
+ # rset = JSON.parse(JSON.dump(rset))
9
+ File.open(filename, 'w') do |file|
10
+ # file.puts rset
11
+ rset.first['log'].each do |iter|
12
+ file.write(JSON.dump(JSON.parse(iter)))
13
+ file.write "\n"
14
+ end
15
+ end
16
+ end
17
+
18
+ get_logs 'mongodb://localhost', 'logs.txt'
data/lib/savedPipeline.rb CHANGED
@@ -14,6 +14,10 @@ def pipeline_to_mongosh_script(infile, outfile)
14
14
  the_pipeline = "[\n"
15
15
  is_first = true
16
16
  data['pipeline'].each do |pstage|
17
+ if not pstage["isEnabled"]
18
+ next
19
+ end
20
+
17
21
  if is_first
18
22
  is_first = false
19
23
  else
metadata CHANGED
@@ -1,23 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongogems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
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-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.14.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.14.0
13
27
  description:
14
28
  email:
15
29
  executables:
16
30
  - compass2mongosh
31
+ - mongolog2file
32
+ - mongoindex2file
17
33
  extensions: []
18
34
  extra_rdoc_files: []
19
35
  files:
20
36
  - bin/compass2mongosh
37
+ - bin/mongoindex2file
38
+ - bin/mongolog2file
39
+ - lib/indexes.rb
40
+ - lib/logs.rb
21
41
  - lib/savedPipeline.rb
22
42
  homepage:
23
43
  licenses: []