mongoid-shell 0.5.0 → 0.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f3fcabc0004e2cacdcac5776ed0d39e594708ec4ec152540b067bd1888dc527
4
- data.tar.gz: 38d3a660fb2dfc72dada952faa2e46d692d5cfe0bf36588572932c76d51975eb
3
+ metadata.gz: d151d5c6417f84292d8238f4bc5a28893815659bad5becea89130f68fa666496
4
+ data.tar.gz: e38a69795fe72838b6ec566d68e6f3226d24f0dad2620cd7a7d6f88b31f19465
5
5
  SHA512:
6
- metadata.gz: 8ffbf1bad9524352f98cd3a8bf1d98e544b9c428580442b85b108fa50de25cf4189e081a1639ab886e710fe60200d1c118dd46ee1c8be7eebe8e757d1371ba48
7
- data.tar.gz: 5b6d190569e9d18542b651658c2b4b8bc58ca836536ac6f54ec6071a5163b19c28b6764fd436f4145c210d989904a0dd3ba7400e099785844593172e79e38135
6
+ metadata.gz: 3d874447600be8860e2cefe755d06d5ef9d3cc9787a7ae1c5903b2b677574bdd542341ef7ecd80d7674d416f32266e1a217507edaa4eb6001a90b3c3396e06c3
7
+ data.tar.gz: d50790638bc957f3d42344e7aa31023bde3b773735708e7358f22a89d0984f91ae17b2e297e2dc16b53b2c357638ae4cf4418eb46bd63e93e6f502e9acddb9fb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.1 (2026/10/15)
2
+
3
+ * [#17](https://github.com/mongoid/mongoid-shell/issues/17): Preserve Extended JSON queries through shell escaping and serialize Hash queries for `mongodump` and `mongoexport` - [@dblock](https://github.com/dblock).
4
+
1
5
  ### 0.5.0 (2026/10/14)
2
6
 
3
7
  * [#25](https://github.com/mongoid/mongoid-shell/pull/25): Add SimpleCov and Coveralls reporting in CI and update status badges - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -84,6 +84,16 @@ mongodump.to_s # mongodump --db test --collection test
84
84
 
85
85
  The `Mongoid::Shell::Commands::Mongodump` class supports `--db`, `--host`, `--username`, `--password`, `--query`, `--out`, `--collection`, `--excludeCollection`, `--excludeCollectionsWithPrefix`, `--directoryperdb`, `--journal`, `--oplog`, `--repair`, `--forceTableScan`, `--dbpath`, `--ipv6`, `--ssl` and `--authenticationDatabase`
86
86
 
87
+ For `mongodump` and `mongoexport`, `query` accepts an Extended JSON string or a Hash containing Extended JSON values. Hashes are serialized as JSON and queries are shell-escaped, preserving operators such as `$eq` and `$date` literally.
88
+
89
+ ```ruby
90
+ mongodump = Mongoid::Shell::Commands::Mongodump.new(
91
+ collection: 'history_trackers',
92
+ query: { scope: { '$eq' => 'offer' }, created_at: { '$gte' => { '$date' => '2019-12-24T09:36:56.312Z' } } }
93
+ )
94
+ system mongodump.to_s
95
+ ```
96
+
87
97
  ### Mongorestore
88
98
 
89
99
  The mongorestore tool imports content from binary database dump, created by mongodump into a specific database.
@@ -60,13 +60,7 @@ module Mongoid
60
60
  when Boolean, TrueClass then key
61
61
  when Array then value.map { |v| "#{key} #{v}" }.join(' ')
62
62
  else
63
- if mask_sensitive && arg[:sensitive]
64
- value = mask_sensitive
65
- else
66
- # TODO: quote other special characters?
67
- value = value.to_s
68
- value = "\"#{value}\"" if value.include? ' '
69
- end
63
+ value = format_value(value, arg, mask_sensitive)
70
64
  key ? "#{key} #{value}" : value
71
65
  end
72
66
  end
@@ -78,6 +72,18 @@ module Mongoid
78
72
 
79
73
  private
80
74
 
75
+ def format_value(value, arg, mask_sensitive)
76
+ return mask_sensitive if mask_sensitive && arg[:sensitive]
77
+
78
+ if arg[:json]
79
+ value = ::JSON.generate(value) if value.is_a?(Hash)
80
+ Shellwords.escape(value.to_s)
81
+ else
82
+ value = value.to_s
83
+ value.include?(' ') ? "\"#{value}\"" : value
84
+ end
85
+ end
86
+
81
87
  if ::Mongoid::Compatibility::Version.mongoid5_or_newer?
82
88
  def default_client_or_session
83
89
  Mongoid.default_client
@@ -18,7 +18,7 @@ module Mongoid
18
18
  option :collection
19
19
  option :excludeCollection
20
20
  option :excludeCollectionsWithPrefix
21
- option :query
21
+ option :query, json: true
22
22
  option :out
23
23
  option :directoryperdb
24
24
  option :journal
@@ -26,7 +26,7 @@ module Mongoid
26
26
  option :collection
27
27
  option :fields
28
28
  option :fieldFile
29
- option :query
29
+ option :query, json: true
30
30
  option :type
31
31
  option :out
32
32
  option :skip
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Shell
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
6
6
  end
7
7
  end
data/lib/mongoid-shell.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'i18n'
4
+ require 'json'
5
+ require 'shellwords'
4
6
 
5
7
  I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
6
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine