在名称和电子邮件字段上以特定字母开头的“喜欢”实现查询MongoDB?
对于MongoDB中的“赞”实现,请使用//并在两者之间设置该特定字母。例如-
/J/
让我们创建一个包含文档的集合-
> db.demo554.insertOne({"UserName":"John","UserMailId":"John@gmail.com"});{
"acknowledged" : true, "insertedId" : ObjectId("5e8f1cfed1d72c4545cb8679")
}
> db.demo554.insertOne({"UserName":"Chris","UserMailId":"Chris@gmail.com"});{
"acknowledged" : true, "insertedId" : ObjectId("5e8f1d0cd1d72c4545cb867a")
}
> db.demo554.insertOne({"UserName":"Jace","UserMailId":"Jace@gmail.com"});{
"acknowledged" : true, "insertedId" : ObjectId("5e8f1d1cd1d72c4545cb867b")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo554.find();
这将产生以下输出-
{ "_id" : ObjectId("5e8f1cfed1d72c4545cb8679"), "UserName" : "John", "UserMailId" : "John@gmail.com" }
{ "_id" : ObjectId("5e8f1d0cd1d72c4545cb867a"), "UserName" : "Chris", "UserMailId" : "Chris@gmail.com" }
{ "_id" : ObjectId("5e8f1d1cd1d72c4545cb867b"), "UserName" : "Jace", "UserMailId" : "Jace@gmail.com" }以下是对“like”实现的查询-
> db.demo554.find({
... "$or": [
... { "UserName": /J/ },
...
... { "UserMailId": /J/ }
... ]
... }
... );这将产生以下输出-
{ "_id" : ObjectId("5e8f1cfed1d72c4545cb8679"), "UserName" : "John", "UserMailId" : "John@gmail.com" }
{ "_id" : ObjectId("5e8f1d1cd1d72c4545cb867b"), "UserName" : "Jace", "UserMailId" : "Jace@gmail.com" }热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练