中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何進行MongoDB排除查詢$ne缺陷

發布時間:2021-11-03 10:44:33 來源:億速云 閱讀:492 作者:柒染 欄目:關系型數據庫

本篇文章給大家分享的是有關如何進行MongoDB排除查詢$ne缺陷,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

    最近學習MongoDB數據庫基本開發知識,發現MongoDB的排除查$ne類似于Oracle的not in 或者not exists,

但是$ne只能對字符串鍵值對起作用而對數字類型不行,舉例如下:

示例數據:

> dvd=({"Type":"DVD","Title":"Matrix,The","Released":1999,"Cast":["Keanu Reeeves","Carrie-Anne Moss","Laurence Fishburne","Hugo Weaving","Gloria Foster","Joe Pantoliano"]})

{

"Type" : "DVD",

"Title" : "Matrix,The",

"Released" : 1999,

"Cast" : [

"Keanu Reeeves",

"Carrie-Anne Moss",

"Laurence Fishburne",

"Hugo Weaving",

"Gloria Foster",

"Joe Pantoliano"

]

}

> db.media.insert(dvd)

WriteResult({ "nInserted" : 1 })

> dvd=({"Type":"DVD","Title":"Blade Runner","Released":1982})

{ "Type" : "DVD", "Title" : "Blade Runner", "Released" : 1982 }

> db.media.insert(dvd)

WriteResult({ "nInserted" : 1 })

> dvd=({"Type":"DVD","Title":"Toy Story 3","Released":2010})

{ "Type" : "DVD", "Title" : "Toy Story 3", "Released" : 2010 }

> db.media.insert(dvd)

WriteResult({ "nInserted" : 1 })

>

正常的字符串排除查詢,以示例數據中Title鍵進行測試:

> db.media.find({"Type":"DVD","Title":{$ne:"Blade Runner"}})

{ "_id" : ObjectId("595af5ce39297105e4322fbd"), "Type" : "DVD", "Title" : "Matrix,The", "Released" : 1999, "Cast" : [ "Keanu Reeeves", "Carrie-Anne Moss", "Laurence Fishburne", "Hugo Weaving", "Gloria Foster", "Joe Pantoliano" ] }

{ "_id" : ObjectId("595af63239297105e4322fbf"), "Type" : "DVD", "Title" : "Toy Story 3", "Released" : 2010 }

>

對數字排除無效,以示例數據中Released鍵進行測試:

> db.media.find({"Type":"DVD","Release":{$ne:"1999"}})

{ "_id" : ObjectId("595af5ce39297105e4322fbd"), "Type" : "DVD", "Title" : "Matrix,The", "Released" : 1999, "Cast" : [ "Keanu Reeeves", "Carrie-Anne Moss", "Laurence Fishburne", "Hugo Weaving", "Gloria Foster", "Joe Pantoliano" ] }

{ "_id" : ObjectId("595af61939297105e4322fbe"), "Type" : "DVD", "Title" : "Blade Runner", "Released" : 1982 }

{ "_id" : ObjectId("595af63239297105e4322fbf"), "Type" : "DVD", "Title" : "Toy Story 3", "Released" : 2010 }

>

> db.media.find({"Type":"DVD","Release":{$ne:1999}})

{ "_id" : ObjectId("595af5ce39297105e4322fbd"), "Type" : "DVD", "Title" : "Matrix,The", "Released" : 1999, "Cast" : [ "Keanu Reeeves", "Carrie-Anne Moss", "Laurence Fishburne", "Hugo Weaving", "Gloria Foster", "Joe Pantoliano" ] }

{ "_id" : ObjectId("595af61939297105e4322fbe"), "Type" : "DVD", "Title" : "Blade Runner", "Released" : 1982 }

{ "_id" : ObjectId("595af63239297105e4322fbf"), "Type" : "DVD", "Title" : "Toy Story 3", "Released" : 2010 }

>

實驗結果:mongodb的$ne操作只能對字符串鍵值對發揮作用。

本次實驗的MongoDB數據庫版本是:3.2.7

以上就是如何進行MongoDB排除查詢$ne缺陷,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

义马市| 绩溪县| 淮安市| 岑溪市| 屯昌县| 阳原县| 称多县| 龙陵县| 鹤壁市| 明溪县| 台湾省| 安乡县| 海兴县| 汕尾市| 四平市| 云南省| 沙河市| 乐安县| 攀枝花市| 兰溪市| 南澳县| 东乌珠穆沁旗| 屏边| 沂南县| 安塞县| 盐山县| 韶关市| 钦州市| 田林县| 恩施市| 安陆市| 普定县| 江西省| 仙居县| 泽州县| 社会| 台北市| 南木林县| 九龙城区| 报价| 耒阳市|