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

$cond operator should allow $match as a boolean expression

    • Query Execution
    • Fully Compatible

      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)

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            dillonkrug Dillon Krug
            Votes:
            3 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: