Atomics can be compared with the usual six comparison operators (equality, non-equality, lower-than, greater-than, lower-or-equal, greater-or-equal), and with the same two-letter symbols as in MongoDB.

1 + 1 eq 2, 1 lt 2

Comparison is only possible between two compatible types, otherwise, an error is raised.

"foo" eq 1

null can be compared for equality or inequality to anything - it is only equal to itself so that false is returned when comparing if for equality with any non-null atomic. True is returned when comparing it with non-equality with any non-null atomic.

1 eq null, "foo" ne null, null eq null

For ordering operators (lt, le, gt, ge), null is considered the smallest possible value (like in JavaScript).

1 lt null

Like for arithmetic operations, if an operand is the empty sequence, the empty sequence is returned as well.

() eq 1

Comparisons and logic operators are fundamental for a query language and for the implementation of a query processor as they impact query optimization greatly. The current comparison semantics for them is carefully chosen to have the right characteristics as to enable optimization.