java - MongoDb:Java 中的正则表达式慢
问题描述
因此,如果我运行以下查询,则只需不到 5 秒
db.RawURLS.find({"url" : { $regex : /^https:\/\/en.wikipedia.org/ }}).count()
如果我做我认为在 Java 中相同的事情,则需要更长的时间
MongoClient mongoClient = MongoClients.create(mainMongo);
MongoDatabase database = mongoClient.getDatabase(mongoDatabase);
MongoCollection<Document> collection = database.getCollection(urlTable);
Document regQuery = new Document();
regQuery.append("$regex", "^(?)" + Pattern.quote("https://en.wikipedia.org/"));
regQuery.append("$options", "i");
Document findQuery = new Document();
findQuery.append("url", regQuery);
MongoCursor<Document> cursor = collection.find(findQuery).iterator();
我有错误吗?
我有一个名为 URL 的字段,例如,我想检查它是否以 XYZ 开头。该 URL 已编入索引。
解决方案
推荐阅读
- django - django 添加新模型字段时显示错误
- python - for循环并在Python中添加额外的列groupby pandas dataframe
- javascript - 如何在 hello world 前 5 秒显示活动指示器
- vb.net - 用户代码未处理 ArgumentException:参数“名称”不能为空、空或仅包含空格
- android-gradle-plugin - Gradle 任务在新版 Android Studio 中不可见
- apache-kafka - 如何使用 kafka 扩展 Zookeeper
- git - 推送到受保护的分支
- r - 如何在 data.table 中找到特定字符串的行号和列号?
- readdir - 如何仅获取某个目录中的子目录名称
- ios - 连接到 janus 服务器总是挂起,并带有来自 janus 的挂断消息