const string Pattern = @"(?si)<([^\s<]*totalWork[^\s<]*)>.*?</\1>";
var filter = Builders<JobInfoRecord>.Filter.Regex(x => x.SerializedBackgroundJobInfo,
new BsonRegularExpression(Pattern, "i"));
var documents = await records.Find(filter).ToListAsync();
====
得到后,我将documents
处理我身边的每个文档。
const string EmptyTag = "<$1></$1>";
var updatedJobInfo = Regex.Replace(document.SerializedBackgroundJobInfo, Pattern, EmptyTag);
我该怎么办Regex.Replace
?还是只能在客户中发生?
Replace
在Mongo方面有以下作品吗?
using (var cursor = await jobInfoDocuments.FindAsync<JobInfoRecord>(filter))
{
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
foreach (var document in batch)
{
var newInfo = Regex.Replace(document.SerializedBackgroundJobInfo, regex, EmptyTag);
// Applying several operations within the one request.
operationList.Add(new UpdateOneModel<JobInfoRecord>(Builders<JobInfoRecord>.Filter.Eq("_id", document.JobId),
Builders<JobInfoRecord>.Update.Set("SerializedBackgroundJobInfo", newInfo)));
}
您可以使用它,javascript
但请确保该修复程序filter
可与mongo shell一起使用
db.records.find(filter).forEach(function (doc) {
var pattern = /<([^\s<]*totalWork[^\s<]*)>[\s\S]*?</\1>/i;
var EmptyTag = "<$1></$1>";
doc.SerializedBackgroundJobInfo = doc.SerializedBackgroundJobInfo.replace(pattern, EmptyTag);
db.records.save(doc);
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句