Hello,
As you’ve probably seen, it’s not possible to match a null
value on an index. But this is where index bindings shine.
To make use of them in this case, you’ll first create an index using a binding where field2
is null
, then perform a Union
on that index and the one created for field2
being true (this is using a collection called structure_change
, you’ll want to update the source
to whatever your actual collection is called):
CreateIndex({
name: "after_change",
unique: false,
serialized: true,
source: Collection("structure_change"),
terms: [
{
field: ["data", "field2"]
}
]
})
CreateIndex({
name: "sc_by_null_field2",
source: [{
collection: Collection("structure_change"),
fields: {
null_field2: Query(
Lambda(
"doc",
Equals(Select(["data", "field2"], Var("doc"), null), null)
)
)
}
}],
terms: [ {binding: "null_field2"} ],
})
So now when you run a Union
you’ll get both documents back:
Map(
Paginate(
Union(
Match(Index("after_change"), true),
Match(Index("sc_by_null_field2"),true)
)
),
Lambda("doc", Get(Var("doc")))
)
{
data: [
{
ref: Ref(Collection("structure_change"), "300846027025416713"),
ts: 1623167979290000,
data: {
fieldA: "test"
}
},
{
ref: Ref(Collection("structure_change"), "300846100224410121"),
ts: 1623168049112000,
data: {
fieldA: "test2",
field2: true
}
}
]
}