小编Vee*_*Vee的帖子

如何将两个数组转换为 mongoDB 中的对象,其中第一个数组具有多个相同的值

在使用 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 聚合

mongodb mongodb-query mongodb-compass

5
推荐指数
1
解决办法
109
查看次数

如何使用正则表达式来匹配所有可能包含停用词列表的句子?

目标是找到在短语之间可能包含停用词列表的所有句子,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并且有一个正则表达式,无论列表中每个字符串之间有一个或多个停用词的长度如何,都可以工作。

javascript regex typescript

2
推荐指数
1
解决办法
588
查看次数