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
作業系統是:Red Hat Enterprise Linux Server release 6.4 (Santiago)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29357786/viewspace-2141567/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MongoDB - 聚合查詢MongoDB
- ❖ MongoDB 高階查詢MongoDB
- mongodb慢查詢分析MongoDB
- Mongodb高階查詢MongoDB
- MongoDB查詢條件MongoDB
- MongoDB查詢總結MongoDB
- Laravel使用MongoDB複雜的查詢LaravelMongoDB
- MongoDB查詢內嵌文件MongoDB
- MongoDB 常用查詢語法MongoDB
- MongoDB日期型別查詢MongoDB型別
- MongoDB慢查詢與索引MongoDB索引
- Mongodb 關聯表查詢MongoDB
- SpringBoot 框架MongoDB 簡單的查詢方式Spring Boot框架MongoDB
- MongoDB(12)- 查詢嵌入文件的陣列MongoDB陣列
- MongoDB 如何支援類 SQL 查詢MongoDBSQL
- mongodb條件查詢不等於MongoDB
- MongoDB 操作文件 查詢文件MongoDB
- Sublime Text 查詢時排除指定的資料夾或檔案
- MongoDB(13)- 查詢操作返回指定的欄位MongoDB
- JAVA - mongodb 聚合幾種查詢方式JavaMongoDB
- mongodb如何查詢最後幾項?MongoDB
- Spring Boot MongoDB 查詢操作 (BasicQuery ,BSON)Spring BootMongoDB
- Laravel MongoDB 時間區間查詢的問題LaravelMongoDB
- 基於 MongoTemplate 實現MongoDB的複雜查詢MongoDB
- MongoDB 怎麼計運算元查詢MongoDB
- Python全棧MongoDB資料庫(資料的查詢)Python全棧MongoDB資料庫
- Python全棧 MongoDB 資料庫(資料的查詢)Python全棧MongoDB資料庫
- python資料庫-mongoDB的高階查詢操作(55)Python資料庫MongoDB
- ElasticSearch多層nested查詢、nested過濾排除非結果內容Elasticsearch
- 深入理解mongodb查詢條件語句MongoDB
- MongoDB資料庫中查詢資料(下)MongoDB資料庫
- 在MongoDB資料庫中查詢資料(上)MongoDB資料庫
- SQL查詢的:子查詢和多表查詢SQL
- mongoDB高階查詢這一篇就夠了MongoDB
- MongoDB查詢如何只輸出部分欄位內容MongoDB
- MongoDB隨機查詢返回一條或N條記錄的方法MongoDB隨機
- group by,having查詢 ”每**“的查詢
- 使用Spring Reactive MongoDB進行自定義更新查詢 -Yuri MednikovSpringReactMongoDB
- 技術乾貨| MongoDB如何查詢Null或不存在的欄位?MongoDBNull