我有一个可能包含动态值的mongodb查询,例如
[{$group: { _id: '$os_name', count: { $sum: 1 } }},{$sort:{count:-1}},{$out:'newc'},{$group: { _id: '$os_name', count: { $sum: 1 } }}]
[{$group: { _id: '$browser', count: { $sum: 1 } }},{$sort:{count:-1}},{$out:'deffC'}]
我希望在没有,{$out:'anything'}
最终结果是
[{$group: { _id: '$os_name', count: { $sum: 1 } }},{$sort:{count:-1}},{$group: { _id: '$os_name', count: { $sum: 1 } }}]
[{$group: { _id: '$browser', count: { $sum: 1 } }},{$sort:{count:-1}}]
答案 0 :(得分:0)
匹配该字符串的正则表达式为:/,\{\$out:'.*'\}/g
let s = `[{$group: { _id: '$os_name', count: { $sum: 1 } }},{$sort:{count:-1}},{$out:'newc'},{$group: { _id: '$os_name', count: { $sum: 1 } }}]
[{$group: { _id: '$browser', count: { $sum: 1 } }},{$sort:{count:-1}},{$out:'deffC'}]`;
s = s.replace(/,\{\$out:'.*'\}/g, '');
console.log(s);