mongodb $ifNull
生活随笔
收集整理的這篇文章主要介紹了
mongodb $ifNull
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
$ifNull用于判斷第一個表達式是否為 NULL,如果為 NULL 則返回第二個參數(shù)的值,如果不為 NULL 則返回第一個參數(shù)的值。
$ifNull表達式格式為:
{ $ifNull: [ <expression>, <replacement-expression-if-null> ] }例子:
原始數(shù)據(jù):
{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 } { "_id" : 2, "item" : "abc2", description: null, qty: 200 } { "_id" : 3, "item" : "xyz1", qty: 250 }處理語句:
db.inventory.aggregate([{$project: {item: 1,description: { $ifNull: [ "$description", "Unspecified" ] }}}] )結果:
{ "_id" : 1, "item" : "abc1", "description" : "product 1" } { "_id" : 2, "item" : "abc2", "description" : "Unspecified" } { "_id" : 3, "item" : "xyz1", "description" : "Unspecified" }總結
以上是生活随笔為你收集整理的mongodb $ifNull的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里云 centos ssh key 客
- 下一篇: Datalogic得利捷发布IMPACT