在使用 mongo 聚合进行一些处理后,我有一个类似的集合:
[{
field1: 10,
field2: 50,
field3: {
name: ["a","b","a","a"],
value: [1,2,3,4]
}
},...]
Run Code Online (Sandbox Code Playgroud)
我正在努力寻找一种方法将其转换为:
[{
field1: 10,
field2: 50,
a:[1,3,4],
b:[2]
},...]
Run Code Online (Sandbox Code Playgroud)
在 mongoshell 或指南针中使用 mongo 聚合
目标是找到在短语之间可能包含停用词列表的所有句子,to_match如下所示:
let stopword: string[]= ["of", "the", "a"];
let to_match : string = "make wish";
let text: string = "make wish wish make a wish wish wish make the a wish make";
Run Code Online (Sandbox Code Playgroud)
我只能make wish使用这个正则表达式进行匹配:
const regex = new RegExp(`(?:\\b)$to_match(?:\\b)`, "gi");
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以做类似的事情
let to_match_splitted: string[] = to_match.split(" ");
const regex = `(?:\\b)${to_match_splitted[0]}\s(${any(stopword)}?)+\s${to_match_splited[1]}(?:\\b)`;
Run Code Online (Sandbox Code Playgroud)
与any(stopword)停用词列表中的任何停用词相匹配。
to_match_splitted并且有一个正则表达式,无论列表中每个字符串之间有一个或多个停用词的长度如何,都可以工作。