mongogems 0.0.6 → 0.0.7

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: 76e7dbd3e0694f3ad409e13c3530ed907a4d828281bec0f3f964e63cf3cc706c
4
- data.tar.gz: c59ee55d845c14dac46e17d6dbcf0ba10b2242d9623839c94b212c92b9f7499a
3
+ metadata.gz: d6b110efba52c4efdfb689e7af26b0e97870e13ac53c03624649c4f4b8f3c7a2
4
+ data.tar.gz: eec7fa33083d44430f3f9b2d4934ba1bea15ba714284fb07b58c3852dbb24a59
5
5
  SHA512:
6
- metadata.gz: 941bf504d23cb010f8c21293c161788cb45d38e91e85aaaa3bd4dc2c9f5c70c9be0c240823c363889645d8f7d416af92dc380823706a6560a445bb2dc2458918
7
- data.tar.gz: b9616a4cfd7458dc0bb1deb57b29c4dae8becff446fbef902fab8f00f60e4ce8eec616f70279c4393a9bc1c635b8a9e9fc862cb27a9ff825ca7416922824cd0e
6
+ metadata.gz: 6d93488d894bc85eb43b3713b98b00a8d13cc448c60649ecad754efab53c61ccbc99534d1b77da74de3e1a36b3c79e70ef24b0bef15c36585724cbef798df180
7
+ data.tar.gz: 2a26b5a049cba6a60519d8045dae7edba880308a236eec7405fee626544008f466c17b152cfc4be51f6d913c27739f922e3de97b10fc78db85e714f74dad7455
data/bin/mg ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require_relative '../lib/config'
4
+ require 'shellwords'
5
+
6
+ options = {}
7
+
8
+ case ARGV.shift
9
+ when 'config'
10
+ options[:cmd] = 'config'
11
+ case ARGV.shift
12
+ when 'set'
13
+ options[:subcmd] = 'set'
14
+ key = ARGV.shift
15
+ value = ARGV.join ' '
16
+ options[:key] = key
17
+ options[:val] = value
18
+
19
+ write_config_entry options[:key], options[:val]
20
+ when 'get'
21
+ options[:subcmd] = 'get'
22
+ key = ARGV.shift
23
+ options[:key] = key
24
+
25
+ val = read_config_entry options[:key]
26
+ puts "Config for #{options[:key]} is #{val}"
27
+ when 'help'
28
+ puts '
29
+ Usage: mg config [subcommand] ...
30
+ Commands:
31
+ get KEY
32
+ set KEY VALUE
33
+ '
34
+ exit
35
+ else
36
+ puts "Unrecognized #{options[:cmd]} command"
37
+ exit -1
38
+ end
39
+ when 'help', '--help', '-h', '-?'
40
+ puts '
41
+ Usage: mg [command] [subcommand] ...
42
+ Commands:
43
+ config
44
+ help
45
+ '
46
+ exit
47
+ when 'shell', 's'
48
+ options[:cmd] = 'shell'
49
+ m_uri = read_config_entry 'uri'
50
+ if m_uri.nil?
51
+ puts 'URI not found in config.
52
+ Must set URI with: mg config set uri YOUR_URI_HERE
53
+ Example: mg config set uri \'mongodb://username:password@localhost:27017\'
54
+ '
55
+ exit
56
+ end
57
+ remaining_cmds = ARGV.map{|arg| Shellwords.escape arg}.join ' '
58
+ cmdstr = "mongo #{m_uri} #{remaining_cmds}"
59
+ exec(cmdstr)
60
+ # when 'echo'
61
+ # remaining_cmds = ARGV.map{|arg| Shellwords.escape arg}.join ' '
62
+ # puts remaining_cmds
63
+ # exec("echo #{remaining_cmds}")
64
+ else
65
+ puts 'Unrecognized command'
66
+ exit -1
67
+ end
68
+
69
+
data/lib/config.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ $config_filename = File.join(Dir.home, '.mongogems')
4
+ $has_config = lambda { File.exists? $config_filename }
5
+
6
+ # Write a key-value pair to the config file
7
+ def write_config_entry(key, value)
8
+ if $has_config.call then
9
+ curr_config = YAML.load(File.read($config_filename))
10
+ else
11
+ curr_config = {}
12
+ end
13
+
14
+ curr_config[key] = value
15
+
16
+ File.open($config_filename, 'w') { |f| f.write(curr_config.to_yaml) }
17
+ end
18
+
19
+ # Reads a key-value pair from the config file
20
+ def read_config_entry(key)
21
+ if $has_config.call then
22
+ curr_config = YAML.load(File.read($config_filename))
23
+ else
24
+ return nil
25
+ end
26
+
27
+ curr_config[key]
28
+ end
29
+
30
+ # write_config_entry 'mongouri', 'mongodb://localhost'
31
+ # p (read_config_entry 'mongouri')
data/lib/indexes.rb CHANGED
@@ -4,7 +4,6 @@ require 'json'
4
4
  def get_indexes_script(uri, db_name=nil, coll_name=nil, outfile)
5
5
  client = Mongo::Client.new(uri)
6
6
 
7
-
8
7
  db_list = []
9
8
  if not db_name.nil?
10
9
  db_list.push db_name
@@ -15,18 +14,11 @@ def get_indexes_script(uri, db_name=nil, coll_name=nil, outfile)
15
14
  end
16
15
  end
17
16
 
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
17
  scripts = []
26
18
 
27
19
  db_list.each do |iter_db|
28
20
  client = client.use iter_db
29
- scripts.push "use #{iter_db};"
21
+ scripts.push "db = db.getSiblingDB('#{iter_db}')';"
30
22
  if coll_name.nil?
31
23
  colls = client.collections
32
24
  else
@@ -70,6 +62,3 @@ def gen_idx_script(idIndex, collname)
70
62
  opt_spec = JSON.dump idx_options
71
63
  txt = "db.#{collname}.createIndex(#{idx_spec}, #{opt_spec});"
72
64
  end
73
-
74
- # mdb_uri = 'mongodb://localhost'
75
- # get_indexes_script mdb_uri, nil, nil, 'idx_out.txt'
data/lib/savedPipeline.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require 'json'
2
- # require 'hjson'
3
2
 
4
- # filename = '/Users/nitin/Downloads/Zaloni-DQ-A/607d7460cb21963a143d1d0f.json'
5
3
 
4
+ # Exports the pipeline to a .aggregate() Mongo shell script
6
5
  def pipeline_to_mongosh_script(infile, outfile)
7
6
  txt = File.read(infile)
8
7
  data = JSON.parse(txt)
@@ -42,6 +41,7 @@ db.getSiblingDB('#{dbname}').#{collname}.aggregate(
42
41
  end
43
42
 
44
43
 
44
+ # Exports the pipeline to a createView Mongo shell script
45
45
  def pipeline_to_view_mongosh_script(infile, viewname, outfile)
46
46
  txt = File.read(infile)
47
47
  data = JSON.parse(txt)
@@ -78,5 +78,3 @@ db.getSiblingDB('#{dbname}').createView('#{viewname}', '#{collname}',
78
78
 
79
79
  File.write(outfile, mongosh_script_out)
80
80
  end
81
-
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.6
4
+ version: 0.0.7
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-11 00:00:00.000000000 Z
11
+ date: 2021-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -24,18 +24,49 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: shellwords
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
27
55
  description:
28
56
  email:
29
57
  executables:
30
58
  - compass2mongosh
31
59
  - mongolog2file
32
60
  - mongoindex2file
61
+ - mg
33
62
  extensions: []
34
63
  extra_rdoc_files: []
35
64
  files:
36
65
  - bin/compass2mongosh
66
+ - bin/mg
37
67
  - bin/mongoindex2file
38
68
  - bin/mongolog2file
69
+ - lib/config.rb
39
70
  - lib/indexes.rb
40
71
  - lib/logs.rb
41
72
  - lib/savedPipeline.rb