我正在试图弄清楚如何搜索关键字的每个实例的集合。例如,我想为“已验证”一词的每个实例搜索一个集合。下面是包含关键字的集合中的一个文档:
{
"_id": {
"$oid": "55945938d28f9f3809002afc"
},
"TAGS": ".source.s_net",
"SOURCEIP": "10.10.0.5",
"SEQNUM": "11004",
"PROGRAM": "Core",
"PRIORITY": "info",
"MESSAGE": "<pppoe-jjcutter>: authenticated",
"LEGACY_MSGHDR": "Core ",
"HOST_FROM": "10.10.0.5",
"HOST": "10.10.0.5",
"FACILITY": "syslog",
"DATE": "Jul 1 14:18:48"
}
答案 0 :(得分:0)
检查我的github https://github.com/parthaindia/CustomMongo,
getByCondition(String tableName,Map condition),调用此方法,其中tableName是您的集合名称,Map是key-value。在您的案例图中将是
Map condition = new HashMap();
condition.put(&#34; MESSAGE&#34;,&#34;:经过身份验证&#34;); //或任何对象
您将收到Json格式的数组列表。使用类型标记转换为数组列表。
答案 1 :(得分:0)
您可以使用通配符文本索引 测试数据
ScheduleID DateTime Team-1 Team-2
----------------------------------------------------------------------------------------
1 April, 18 2008 20:00:00 Royal Challengers Bangalore Kolkata Knight Riders
2 April, 19 2008 17:00:00 Chennai Super Kings Kings XI Punjab
3 April, 19 2008 20:30:00 Delhi Daredevils Rajasthan Royals
4 April, 20 2008 16:30:00 Kolkata Knight Riders Deccan Chargers
5 April, 20 2008 20:00:00 Royal Challengers Bangalore Mumbai Indians
通配符索引
db.people.insert({name: "Martin", remarks: "great architector"})
db.people.insert({name: "John", remarks: "awesome SO user, great programmer"})
db.people.insert({name: "Tony The Great", remarks: "inventor"})
查询
db.people.createIndex({"$**" : "text"})
您将获得所有3条记录 MongoDB documentation on wildcard indexes
答案 2 :(得分:0)
使用$regex查找如下:
db.messages.find({"MESSAGE":{"$regex":"(\\s|^)authenticated(\\s|$)"}})
或者,如果您想查找authenticated
值的完全匹配,请在查询下方使用
db.messages.find({"MESSAGE":"authenticated"})