Condition query is stored as an object instead of being run to store a boolean

Hi,
With Node driver, inside an operation to be passed to a transaction, I try to run a condition in order to store a boolean as a result of the condition, but what is stored is the condition query itself.

The part of the query:

…
$set: {
    'questions.$[question].conditionnelle': {
        $gt: [{ $size: '$questions.$[question].conditions' }, 0],
        },
    },
…

The result inside my collection:

"conditionnelle": {
        "$gt": [
          {
            "$size": "$questions.$[question].conditions"
          },
          0
        ]
      },

What am I missing here?

It is hard to tell because you did not share where and how you use $set.

But most likely you are missing [ ] around $set as documented in update with aggregation.

Thank you @steevej for your answer.

Here is the complete operations array building:

const operations = [
	{
		collection: 'questionnaires',
		operation: 'updateMany',
		filtres: {
			_id: filtres.questionnaire_id,
		},
		champs: {
			$pull: {
				'questions.$[question].conditions': {
					parent_id: champs.question_id,
				},
			},
			$set: {
				'questions.$[question].conditionnelle': {
					$gt: [{ $size: '$questions.$[question].conditions' }, 0],
				},
			},
		},
		options: {
			arrayFilters: [
				{
					'question._id': {
						$in: questions_conditionnees,
					},
				},
			],
		},
	},
	{
		collection: 'questionnaires',
		operation: 'updateOne',
		filtres: { _id: filtres.questionnaire_id },
		champs: { $pull: { questions: { _id: champs.question_id } } },
	},
]

This array is then passed to this function that makes use of a transaction:

function requete(operations) {
	const session = client.startSession()

	try {
		const resultats = []

		await session.withTransaction(async () => {
			for (const operation of operations) {
				const db = client.db(process.env.DB_NAME)
				const col = db.collection(operation.collection)
				await col[operation.operation](
					operation.filtres,
					operation.champs,
					operation.options
				).then(resultat => {
					resultats.push(resultat)
				})
			}
		})

		return resultats
	} catch (error) {
		logger.error(error, {
			requete: 'transaction.js',
			operations: operations,
		})

		return error
	} finally {
		await session.endSession()
	}
}

I have tried to change the following part, according to the doc you linked:

champs: [
	{
		$pull: {
			'questions.$[question].conditions': {
				parent_id: champs.question_id,
			},
		},
	},
	{
		$set: {
			'questions.$[question].conditionnelle': {
				$gt: [
					{ $size: '$questions.$[question].conditions' },
					0,
				],
			},
		},
	},
],

But I then cannot use a $pull method, here is the error I get: “Unrecognized pipeline stage name: ‘$pull’”

Is there any solution to combine?