mongo-util 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 77460289e675fa2a3a550b5966f055228cddc427
4
- data.tar.gz: c5b3a008606b6ade10db5007914ae9892e503b1c
3
+ metadata.gz: 7ce946a3aab8df1e1933ffd88e4991c992e129a9
4
+ data.tar.gz: a3dfad61ebc465b5f3dad97fbe5b08586e6eba12
5
5
  SHA512:
6
- metadata.gz: f1733d22c5efaf11a19bfa5b487bac8717d60ad6ac8bdbb4cef4f4be05cb73e20db82ac622d1baf86a09177e2c1e628dbeb4a5cb6c893e9e990e6559cc0c8bd2
7
- data.tar.gz: baee2b80c9fb74919250f2704569165641b299be587dcbd08ec65f11c9865e357aaf881fc6380e62f4831461aa3cce036a42acfa031087ea1979fe4df9d27c27
6
+ metadata.gz: 6df06ef07f8ac9ddfb902c09321013bdb314adf2e6ec4739b911a585626be8f244ca185aac6608ac6da2b963f1706300a362f6f8774cc1fb25997df04a683689
7
+ data.tar.gz: 31a9e1d4d32af7fa52be465b1f07825523513bd110771c4a47a77e74d2a8d33a69d9237ce2ab015d4f6b6700b412e5936e8b0d331d5a4c64916a9823df3538db
data/README.md CHANGED
@@ -1,4 +1,71 @@
1
1
  mongo-util
2
2
  ==========
3
3
 
4
- Ruby Interface for copying Mongo Collections from one server to another
4
+ [![Dependency Status](https://gemnasium.com/tonekk/mongo-util.svg)](https://gemnasium.com/tonekk/rails-js)
5
+ [![Gem Version](http://img.shields.io/gem/v/mongo-util.svg)](https://rubygems.org/gems/rails-js)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://tonekk.mit-license.org)
7
+
8
+ Copying over complete databases is not that hard with **mongodb**.
9
+ Use `mongodump` followed by `mongorestore` and there you go.
10
+ But say you want to copy *only certain records from certain collections*, things get a little bit hairy.
11
+
12
+ Why? Can't I just use some javascript and the `mongo`-shell?
13
+ No. Some mongo commands just don't have authentication, so I found it was the easiest way to use `mongorestore` and `mongodump` and wrap them into a handy library.
14
+
15
+
16
+ ## Synopsis
17
+
18
+ ```ruby
19
+
20
+ require 'mongo/util'
21
+
22
+ # Create mongo util instance, set database to fetch from and database to copy to
23
+ # as well as dump folder
24
+ mongo = Mongo::Util.new({ host: 'foo.mongohosting.com', port: 31337, db: 'foo' },
25
+ { db: 'foo_development' },
26
+ 'mongo_dump')
27
+
28
+ # Add authentication
29
+ mongo.from = { user: 'root', password: 'password' }
30
+
31
+ # Iterate over collections
32
+ mongo.collections.each do |collection|
33
+
34
+ # Add some case here
35
+ if collection == 'some.collection'
36
+
37
+ # Add queries here as you like
38
+ mongo.dump(collection: collection, query: { something: false }) &&
39
+ mongo.remove(collection, query: { something: false }) &&
40
+ mongo.restore
41
+
42
+ else
43
+
44
+ # Just copy
45
+ mongo.dump(collection: collection) &&
46
+ mongo.remove(collection) &&
47
+ mongo.restore
48
+
49
+ end
50
+
51
+ # Clean up dump folder
52
+ mongo.clean
53
+ end
54
+
55
+ ```
56
+
57
+ The snippet above is replacing the contents of all collections from `localhost:27017/foo_development` with the ones from `foo.mongohosting.com:31337/foo` (you can also specify an external db to copy to, *localhost:27017* is standard), except for `some.collection`, for which it only replaces the entries where the query `{ something: false }` matches.
58
+
59
+
60
+ ## Installing
61
+
62
+ Install as you would install any other gem.
63
+ [bundler](http://bundler.io/) is your friend!
64
+
65
+ When you're using Rails and you want to use this gem for a script to get fresh production data, just use `bundle exec yourscript.rb`, where *yourscript.rb* contains something like above.
66
+
67
+
68
+ ## Contributing
69
+
70
+ [Fork](https://github.com/tonekk/mongo-util/fork) -> Commit -> Pull Request
71
+ Pull
@@ -1,5 +1,5 @@
1
1
  module Mongo
2
2
  module Util
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/mongo/util.rb CHANGED
@@ -74,7 +74,11 @@ module Mongo
74
74
  raise 'Cannot fetch collections: needs @to[:host], @to[:port], @to[:db]'
75
75
  end
76
76
 
77
- `mongo #{@to[:db]} --host #{@to[:host]} --port #{@to[:port]} --quiet --eval 'db.getCollectionNames()'`.rstrip.split(',')
77
+ cmd = "mongo #{@to[:db]} --host #{@to[:host]} --port #{@to[:port]} --quiet --eval 'db.getCollectionNames()'"
78
+ # Append auth, if neccessary
79
+ cmd += Mongo::Util.authentication(@to)
80
+
81
+ `#{cmd}`.rstrip.split(',')
78
82
  end
79
83
 
80
84
  # Deletes @dump_dir
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn-Lenanrt Heemeyer