MongoDB正则表达式匹配特定记录吗?
首先让我们创建一个包含文档的集合-
> dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "John" },"StudentAge":21 });
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf227acb64a577be5a2bc07")
}
> dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "JOHN" },"StudentAge":19 });
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf227b8b64a577be5a2bc08")
}
> dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "Carol" },"StudentAge":20 });
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf227c2b64a577be5a2bc09")
}以下是在find()方法的帮助下显示集合中所有文档的查询-
> dbworkingOfRegularExpressionDemofind();
这将产生以下文件-
{ "_id" : ObjectId("5cf227acb64a577be5a2bc07"), "StudentDetails" : { "StudentName" : "John" }, "StudentAge" : 21 }
{ "_id" : ObjectId("5cf227b8b64a577be5a2bc08"), "StudentDetails" : { "StudentName" : "JOHN" }, "StudentAge" : 19 }
{ "_id" : ObjectId("5cf227c2b64a577be5a2bc09"), "StudentDetails" : { "StudentName" : "Carol" }, "StudentAge" : 20 }
Following is the regular expression to get the document with StudentName JOHN:
> dbworkingOfRegularExpressionDemofind({'StudentDetailsStudentName': /JOHN/});这将产生以下文件-
{ "_id" : ObjectId("5cf227b8b64a577be5a2bc08"), "StudentDetails" : { "StudentName" : "JOHN" }, "StudentAge" : 19 }热门推荐
7 带清的简短祝福语
10 怎么说祝福语简短
11 对儿子祝福语简短精辟
12 药店祝福语简短10字
13 别人过大寿祝福语简短
14 周末祝福语正能量简短
15 满月100天简短祝福语
16 给宝贝开学祝福语简短
17 拜年啦祝福语大全简短
18 5岁宝宝祝福语简短