How do mysql and mongodb replace a character in a field
This article focuses on "how to replace a character in a field by mysql and mongodb". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to replace a character in a field by mysql and mongodb.
1. Replace the key characters in the mysql field (replace the zjy.zyzhjyy.cn domain name with zjy.zyjyxx.com).
Note: please make a good data backup before operation.
Update cloud_push_log set result_path = replace (result_path, 'zjy.zyzhjyy.cn','zjy.zyjyxx.com')
Cloud_push_log: specify a table name
Result_path: field name
two。 Replace a string in the mongodb field (replace the zjy.zyjyxx.com character with zjy.zyzhjyy.cn).
Note: please make a good data backup before operation.
Db.getCollection ('eventArgs') .find ({' contextFileHost': {'$ne':null}, 'contextFileHost':/\ .zjy\ .zyjxx\ .com /}). ForEach (function (item) {var tmp = String (item.contextFileHost) if (tmp = = null) {print (item.contextFileHost)} else {tmp = tmp.replace (/\ .zjy\ .zyjxx\ .com / g) "\ .zjy\ .zyzhjyy\ .cn") } item.contextFileHost = tmp; db.getCollection ('eventArgs') .save (item); print ("update to" + item.contextFileHost)})
EventArgs: specify tabl
ContextFileHost: field name
(2)。 Nested modification characters (replace zjy.zyjyxx.com domain name with zjy.zyzhjyy.cn)
Db.getCollection ('eventArgs') .find ({' files.origin': {'$ne':null}) 'files.origin':/\ .zjy\ .zyjyxx\ .com /}) .forEach (function (item) {var tmp = String (item.files.origin) if (tmp = = null) {print (item.files.origin)} else {tmp = tmp.replace (/\ .zjy\ .zyjxx\ .com / g, "\ .zjy\ .zyzhjyy\ .cn") } item.files.origin= tmp; db.getCollection ('eventArgs') .save (item); print ("update to" + item.files.origin)})
EventArgs: table name
Files.origin:files is the first-level field name and origin is the second-level field name.
(3) with array batch update data in the field (replace the zjy.zyjyxx.com domain name with zjy.zyzhjyy.cn)
Note: please make a good data backup before operation.
Db.getCollection ('convert_state_copy0515-1'). Find ({'executeArgs.source':new RegExp (". * zjy.zyjyxx.com.*")}) .forEach (function (item) {var executeArgs = item [' executeArgs']; for (var i in executeArgs) {var source = executeArgs [I] ['source']) If (null! = source & & String (source) .search ('zjy.zyjyxx.com') >-1) {executeArgs [I] [' source'] = source.replace ('zjy.zyjyxx.com',' zjy.zyzhjyy.cn');} var callback = executeArgs [I] ['callback'] If (null! = callback) {var callback_url = executeArgs [I] ['callback'] [' url'] If (null! = callback_url & & String (callback_url) .search ('zjy.zyjyxx.com') >-1) {executeArgs [I] [' callback'] ['url'] = callback_url.replace (' zjy.zyjyxx.com', 'zjy.zyzhjyy.cn') }} var upload = executeArgs [I] ['upload']; if (null! = upload) {var upload_url = executeArgs [I] [' upload'] ['url'] If (null! = upload_url & & String (upload_url) .search ('zjy.zyjyxx.com') >-1) {executeArgs [I] [' upload'] ['url'] = upload_url.replace (' zjy.zyjyxx.com', 'zjy.zyzhjyy.cn') } db.getCollection ('convert_state_copy0515-1') .update ({"_ id": item ['_ id']}, {$set: {"executeArgs": executeArgs, "exec": 1}});})
Convert_state_copy0515-1: table name
ExecuteArgs.source: field name
Source,callback,upload: field name
At this point, I believe you have a deeper understanding of "how to replace a character in a field by mysql and mongodb". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!