Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9606

$cond operator should allow $match as a boolean expression

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible

      Description

      When using $cond in projections, it would be useful to have $match as a boolean expression.

      Use Case:

       
      db.objects.aggregate([
      	{
      		$match: { status: "active" }
      	}, {
      		$project: {
      			name: 1,
      			meta: 1,
      			tags: 1,
      			score: {
      				$add: [
      					{
      						$cond:[{
      							$match: { tags: "a tag I like" }
      						}, 100, 0]
      					}, {
      						$cond:[{
      							$match: { tags: "a tag I really like" }
      						}, 250, 0]
      					}, {
      						$cond:[{
      							$match: { tags: "a tag I dislike" }
      						}, -100, 0]
      					}, {
      						$cond:[{
      							$match: { "meta.promoted": true }
      						}, 1000, 0]
      					}
      				]
      			}
      		}
      	},{
      		$match: { score: { $gt: 0 } }
      	}
      ])
      

      This would eliminate the need to add other $cond expressions like $in (SERVER-6146)

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated: