MongoDB中类似模糊查询操作
更新:HHH   时间:2023-1-7


1.查看集合

show collections

2.向集合中添加数据

db.runoob.insertMany([

{

'title':'data1',

'url':'https://blog.51cto.com/suyanzhu',

'description':'this is data1',

'view':5000

},

{

'title':'data2',

'url':'https://blog.51cto.com/suyanzhu',

'description':'this is data2',

'view':3650

},

{

'title':'data3',

'url':'https://blog.51cto.com/suyanzhu',

'description':'this is data3',

'view':9527

}

])

3.查看所有数据

db.runoob.find().pretty()

4.查询包含指定字符串的数据

// title中包含a1字符串的数据

db.runoob.find({'title':/a1/}).pretty()

5.查询以指定字符串开头的数据

// title以d开头的数据

db.runoob.find({'title':/^d/}).pretty()

6.查询以指定字符串结尾的数据

// title以a3结尾的数据

db.runoob.find({'title':/a3$/}).pretty()

返回MongoDB数据库教程...