日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

MongoDB指定类型查询数据

發布時間:2025/6/15 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MongoDB指定类型查询数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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.insert({

????? ? title: 222,?

????? ? description: 'mongodb',

????? ? by: 'suyanzhu',

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

????? ? tags: ['php','mongodb'],

????? ? likes: 200

})

4.查看所有數據

db.runoob.find().pretty()

5.根據類型查詢數據

// 查詢title類型為字符串的數據

db.runoob.find({'title':{$type:2}}).pretty()

// 或

db.runoob.find({'title':{$type:'string'}}).pretty()


//查詢title類型為數值的數據

db.runoob.find({'title':{$type:1}}).pretty()

// 或

db.runoob.find({'title':{$type:'double'}}).pretty()

轉載于:https://blog.51cto.com/suyanzhu/2307917

總結

以上是生活随笔為你收集整理的MongoDB指定类型查询数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。