溫馨提示×

mongodb如何判斷數據是否存在

小晨
1539
2021-07-08 10:45:21
欄目: 云計算

mongodb判斷數據是否存在的方法:1、打開終端命令行;2、啟動mongodb服務;3、打開mongodb可視化管理工具,編寫shell腳本;4、在腳本中查詢數據時使用$exists方法判斷某字段數據是否存在即可。

mongodb如何判斷數據是否存在

具體內容如下:

使用 $exists 判斷字段是否存在

###### 所有數據

> db.book.find({})

{

    "_id" : ObjectId("58b395fbab449b190054c556"),

    "title" : "MongoDB 教程",

    "description" : "MongoDB 是一個 Nosql 數據庫",

    "owner" : "Knight"

}

/* 2 */

{

    "_id" : ObjectId("58b3960dab449b190054c557"),

    "title" : "MongoDB 教程",

    "description" : "MongoDB 是一個 Nosql 數據庫",

    "owner" : "Knight",

    "date" : "2017-02-27"

}

######查詢所有存在 date 字段的記錄

> db.book.find({date:{$exists:true}})

/* 1 */

{

    "_id" : ObjectId("58b3960dab449b190054c557"),

    "title" : "MongoDB 教程",

    "description" : "MongoDB 是一個 Nosql 數據庫",

    "owner" : "Knight",

    "date" : "2017-02-27"

}

######查詢所有不存在 date 字段的記錄

> db.book.find({date:{$exists:false}})

/* 1 */

{

    "_id" : ObjectId("58b395fbab449b190054c556"),

    "title" : "MongoDB 教程",

    "description" : "MongoDB 是一個 Nosql 數據庫",

    "owner" : "Knight"

}

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女