タイプ'null'
または'objectid'
のフィールドがthe $type
operatorのフィールドと一致するクエリを作成しようとしています。私はちょうどある特定のタイプのクエリを実行すると、それが動作します:フィールドがnullまたは特定のタイプのクエリ
> db.collections.post.findOne({$or: [{x: {$type: 'null'}}]}).then(console.log)
Promise { <pending> }
> { _id: 584f573f931f2b0bf4e3d339,
date: Mon Dec 12 2016 21:04:47 GMT-0500 (Eastern Standard Time),
title: 'hgfgh',
text: 'dhffgh',
userId: 584f573a931f2b0bf4e3d338,
x: null }
私もobjectid
さx
にマッチするクエリを書くとき、私は戻って何を取得:
> db.collections.post.findOne({$or: [{x: {$type: 'null'}}, {x: {$type: 'objectid'}}]}).then(console.log)
Promise { <pending> }
私はリンパ節転移使用していますmongodb-native-2.2。
フィールドがnull
またはObjectId
のいずれかの場合に一致するクエリを作成するにはどうすればよいですか?
あなたは{$ or:{x:{$ type: 'null'}}、{x:{$ type: 'objectId'}}}}オブジェクトIDの大文字Iを使用できますか? – Veeram
それはそれでした。これは私が愚かなxDを感じさせる。 mongoの質問は、これをエラーのように扱い、例外を発生させないことを非難したいと思っています。 – binki