首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> DB2 資料庫 >> DB2 教學

MongoDB 查詢邏輯運算:$and 隱式與顯式用法、$where 條件與多欄位更新技巧

     編輯:DB2 教學

$and 顯式 vs 隱式

-- 顯式 $and
db.coll.find({$and: [{$where: '(1386813645 - this.last_active_time > 300)'}, {status: "online"}]})

-- 隱式 AND (多鍵值並列即為 AND)
db.coll.find({$where: '(1386813645 - this.last_active_time > 300)', status: "online"})

兩者等價,隱式寫法更簡潔。MongoDB 2.0+ 引入顯式 $and 以支援同一欄位多條件或複雜邏輯組合。

同一欄位多條件簡寫

MongoDB Manual: $and Operator

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved