Produced by Araxis Merge on 10/12/2018 4:04:44 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Vetlink 2.0.zip\Vetlink 2.0\vetlink-web.zip\vetlink-web\acceptance_test\selenium-ruby\module | MongoData.rb | Thu Nov 2 15:14:16 2017 UTC |
| 2 | Vetlink 2.0.zip\Vetlink 2.0\vetlink-web.zip\vetlink-web\acceptance_test\selenium-ruby\module | MongoData.rb | Fri Oct 12 13:43:00 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 552 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | #========= ========== ========== ========== ========== ========== ========== ======= | |
| 2 | # USAGE: | |
| 3 | # | |
| 4 | # require File.dirna me(__FILE_ _) + "/Mon goData.rb" | |
| 5 | # | |
| 6 | # | |
| 7 | # METHODS: | |
| 8 | # | |
| 9 | # mc = Mo ngoCollect ion.new(db , collecti on [, mong o_host [, mongo_port ]]) | |
| 10 | # mc.getD ocuments - -> arrayOf Documents | |
| 11 | # mc.size --> integ er - return num ber of doc uments | |
| 12 | # mc.dump ([row]) - display do cument on console (r ow is 1 ba sed) | |
| 13 | # mc.rest oreCollect ion(arrayO fDocuments ) | |
| 14 | # | |
| 15 | # md = mc .getDocume ntBySearch ([searchAr ray]) | |
| 16 | # | |
| 17 | # md.dump - D ump docume nt in buff er | |
| 18 | # md.get( field) - D ump field value that is in buf fer | |
| 19 | # md.repl ace(field, value) - R eplace fie ld value i s in buffe r | |
| 20 | # md.upda te - W rite the d ocument in the buffe r to datab ase | |
| 21 | # | |
| 22 | # | |
| 23 | # EXAMPLE: | |
| 24 | # | |
| 25 | # require File.dirn ame(__FILE __) + "/Mo ngoData.rb " | |
| 26 | # mc = Mo ngoCollect ion.new('e ula','eula Applicatio n') | |
| 27 | # saveDoc s = getDoc uments() # -- Retriev e all docu ments and store them | |
| 28 | # puts mc .size # -- Display size | |
| 29 | # mc.dump () # -- Dump al l onto con sole | |
| 30 | # md = mc .getDocume ntBySearch ([["eulaAg ency", "NA VY"],["app licationKe y", "asthm a"]]) | |
| 31 | # # -- Get a d ocument an d put into buffer | |
| 32 | # puts md .get("appl icationNam e") #-- dis play conte nts of app licationNa me | |
| 33 | # md.repl ace("appli cationName ", "My Per sonal Navy Asthma Ap plication" ) | |
| 34 | # md.repl ace("eulaA gency", "A RMY") #-- Rep lace buffe r contents | |
| 35 | # md.upda te #-- Wri te out buf fer to mon go | |
| 36 | # mc.rest oreCollect ion(saveDo cs) #-- Res tore colle ction cont ents | |
| 37 | # | |
| 38 | #========= ========== ========== ========== ========== ========== ========== ======= | |
| 39 | require 'm ongo' | |
| 40 | include Mo ngo | |
| 41 | ||
| 42 | class Mong oCollectio n | |
| 43 | ||
| 44 | MONGO_URI = "mongodb ://vetlink : IP 7/vetlink? ssl=true&c onnectTime outMS=2000 0&authMech anism=SCRA M-SHA-1&" | |
| 45 | CERT_PAT H = File. join(File. dirname(__ FILE__), " ../data/mo ngodb-cert .crt") | |
| 46 | puts CER T_PATH | |
| 47 | ||
| 48 | ||
| 49 | def init ialize(dat abase, col lection) | |
| 50 | @mongo data_datab ase = data base | |
| 51 | @mongo data_colle ction = co llection | |
| 52 | @docum entArray = [] | |
| 53 | end | |
| 54 | ||
| 55 | ||
| 56 | def getH ost | |
| 57 | return @mongodat a_host | |
| 58 | end | |
| 59 | ||
| 60 | def getP ort | |
| 61 | return @mongodat a_port | |
| 62 | end | |
| 63 | ||
| 64 | def getD B | |
| 65 | return @mongodat a_database | |
| 66 | end | |
| 67 | ||
| 68 | def getC ollection | |
| 69 | return @mongodat a_collecti on | |
| 70 | end | |
| 71 | ||
| 72 | ||
| 73 | ||
| 74 | def getD ocuments | |
| 75 | puts(" \ngetDocum ents in Co llection [ #{@mongoda ta_collect ion}] at h ost=[#{@mo ngodata_ho st}]") | |
| 76 | @docum entArray = [] | |
| 77 | mongo_ client = M ongo::Clie nt.new(MON GO_URI, :s sl_verify => true, : ssl_ca_cer t => CERT_ PATH ) | |
| 78 | db = m ongo_clien t.database | |
| 79 | docume nts = db.c ollection( @mongodata _collectio n).find() | |
| 80 | docume nts.each d o | docume nt | | |
| 81 | @doc umentArray << docume nt | |
| 82 | end | |
| 83 | return @document Array | |
| 84 | ||
| 85 | end | |
| 86 | ||
| 87 | ||
| 88 | ||
| 89 | def size | |
| 90 | return @document Array.size | |
| 91 | end | |
| 92 | ||
| 93 | ||
| 94 | def dump (row=nil) | |
| 95 | puts " Dump of co llection # {@mongodat a_database }.#{@mongo data_colle ction}" | |
| 96 | i = 1 | |
| 97 | @docum entArray.e ach do | d ocument | | |
| 98 | #put s "[#{row} ] [#{i}] #{i == row }" | |
| 99 | if ! row || i = = row | |
| 100 | pu ts "Row #{ i} ------- ---------- ---------- ---------- ---------- ---------- --" | |
| 101 | do cument.eac h do |k, v | | |
| 102 | next if k == '_id' | |
| 103 | puts "key= [#{k}] val ue=[#{v}]" | |
| 104 | en d | |
| 105 | end | |
| 106 | i += 1 | |
| 107 | end | |
| 108 | end | |
| 109 | ||
| 110 | ||
| 111 | def sear chAll(quer y) | |
| 112 | end | |
| 113 | ||
| 114 | ||
| 115 | def sear chAndGetRo w(query) | |
| 116 | i = 1 | |
| 117 | #puts "query=[#{ query}]" | |
| 118 | @docum entArray.e ach do | d ocument | | |
| 119 | resu ltTable = [] | |
| 120 | docu ment.each do |k, v| | |
| 121 | #p uts "searc h.key=[#{k }] value=[ #{v}]" | |
| 122 | qu ery.each d o | qk, qv | | |
| 123 | #puts "que rykey=[#{q k}] queryv alue=[#{qv }]" | |
| 124 | if k == qk | |
| 125 | if v == qv | |
| 126 | result Table << t rue | |
| 127 | else | |
| 128 | result Table << f alse | |
| 129 | end | |
| 130 | end | |
| 131 | en d | |
| 132 | end | |
| 133 | ||
| 134 | #res ultTable.e ach_with_i ndex do | result, ii | | |
| 135 | # p uts "resul tTable[#{i i}] --> #{ result}" | |
| 136 | #end | |
| 137 | sumO fResult = true | |
| 138 | if r esultTable .size > 0 | |
| 139 | re sultTable. each do | result | | |
| 140 | #puts "res ult=#{resu lt}" | |
| 141 | if result == false | |
| 142 | sumOfRes ult = fals e | |
| 143 | end | |
| 144 | en d | |
| 145 | else | |
| 146 | su mOfResult = false | |
| 147 | end | |
| 148 | if s umOfResult | |
| 149 | re turn i | |
| 150 | end | |
| 151 | ||
| 152 | i += 1 | |
| 153 | end | |
| 154 | return 0 | |
| 155 | end | |
| 156 | ||
| 157 | def getD ocumentByS earch(quer y) | |
| 158 | row = searchAndG etRow(quer y) | |
| 159 | if row > 0 | |
| 160 | retu rn MongoDo cument.new (self, get DocumentBy Row(row)) | |
| 161 | else | |
| 162 | retu rn nil | |
| 163 | end | |
| 164 | end | |
| 165 | ||
| 166 | ||
| 167 | def xget DocumentBy Search(que ry) | |
| 168 | row = searchAndG etRow(quer y) | |
| 169 | if row > 0 | |
| 170 | retu rn getDocu mentByRow( row) | |
| 171 | else | |
| 172 | retu rn [] | |
| 173 | end | |
| 174 | end | |
| 175 | ||
| 176 | ||
| 177 | def getD ocumentByR ow(row) | |
| 178 | return @document Array[row- 1] | |
| 179 | end | |
| 180 | ||
| 181 | def remo veCollecti on() | |
| 182 | puts(" Removing C ollection [#{@mongod ata_collec tion}]") | |
| 183 | mongo_ client = M ongo::Clie nt.new(MON GO_URI, :s sl_verify => true, : ssl_ca_cer t => CERT_ PATH ) | |
| 184 | db = m ongo_clien t.database | |
| 185 | db.col lection(@m ongodata_c ollection) .delete_ma ny({}) | |
| 186 | end | |
| 187 | ||
| 188 | ||
| 189 | def rest oreCollect ion(docume nts) | |
| 190 | puts(" Restoring Collection [#{@mongo data_colle ction}]") | |
| 191 | mongo_ client = M ongo::Clie nt.new(MON GO_URI, :s sl_verify => true, : ssl_ca_cer t => CERT_ PATH ) | |
| 192 | db = m ongo_clien t.database | |
| 193 | db.col lection(@m ongodata_c ollection) .delete_ma ny({}) | |
| 194 | docume nts.each d o | docume nt | | |
| 195 | reco rdArray = [] | |
| 196 | docu ment.each do |k, v| | |
| 197 | ne xt if k == '_id' | |
| 198 | re cordArray << [k, v] | |
| 199 | end | |
| 200 | rec ordHash = Hash[recor dArray] | |
| 201 | db. collection (@mongodat a_collecti on).insert _one(recor dHash) | |
| 202 | end | |
| 203 | end | |
| 204 | ||
| 205 | def inse rtit(data_ array) | |
| 206 | puts " inserting. .......... .." | |
| 207 | ## put s "mongo i nsert of . .. #{data_ array}" | |
| 208 | mongo_ client = M ongo::Clie nt.new(MON GO_URI, :s sl_verify => true, : ssl_ca_cer t => CERT_ PATH ) | |
| 209 | db = m ongo_clien t.database | |
| 210 | data_a rray.each do | row| | |
| 211 | db.c ollection( @mongodata _collectio n).insert_ one( row ) | |
| 212 | end | |
| 213 | end | |
| 214 | ||
| 215 | ||
| 216 | ||
| 217 | end | |
| 218 | ||
| 219 | ########## ########## ########## ########## ########## ########## ########## ########## | |
| 220 | ||
| 221 | class Mong oDocument | |
| 222 | ||
| 223 | def init ialize(mc, document) | |
| 224 | @mongo data_docum ent = docu ment.dup | |
| 225 | @mongo data_host = mc.getHo st | |
| 226 | @mongo data_port = mc.getPo rt | |
| 227 | @mongo data_datab ase = mc.g etDB | |
| 228 | @mongo data_colle ction = mc .getCollec tion | |
| 229 | end | |
| 230 | ||
| 231 | def dump | |
| 232 | docume nt = @mong odata_docu ment | |
| 233 | puts " Document D ump ------ ---------- ---------- ---------- ---------- ---------- ---" | |
| 234 | docume nt.each do |k, v| | |
| 235 | next if k == ' _id' | |
| 236 | puts "key=[#{k }] value=[ #{v}]" | |
| 237 | end | |
| 238 | ||
| 239 | end | |
| 240 | ||
| 241 | def repl ace(field, value) | |
| 242 | @mongo data_docum ent[field] = value | |
| 243 | end | |
| 244 | ||
| 245 | def get( field) | |
| 246 | return @mongodat a_document [field] | |
| 247 | end | |
| 248 | ||
| 249 | def upda te | |
| 250 | mongo_ client = M ongo::Clie nt.new(MON GO_URI, :s sl_verify => true, : ssl_ca_cer t => CERT_ PATH ) | |
| 251 | db = m ongo_clien t.database | |
| 252 | idx = @mongodata _document[ "_id"] | |
| 253 | puts " idx=[#{idx }]" | |
| 254 | @mongo data_docum ent.each d o |key, va lue| | |
| 255 | next if key == '_id' | |
| 256 | db.c ollection( @mongodata _collectio n).update( {:_id => idx}, | |
| 257 | {' $set' => { key => val ue}}, | |
| 258 | { :multi => false, :up sert => fa lse} ) | |
| 259 | end | |
| 260 | end | |
| 261 | ||
| 262 | ||
| 263 | ||
| 264 | def toSt r(x) | |
| 265 | #puts "toSTr=[#{ x[0..0]}]" | |
| 266 | if x[0 ..0] == ni l | |
| 267 | retu rn x | |
| 268 | else | |
| 269 | retu rn "\"#{x} \"" | |
| 270 | end | |
| 271 | end | |
| 272 | ||
| 273 | def inse rt | |
| 274 | puts @mongodata _database | |
| 275 | end | |
| 276 | ||
| 277 | end |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.