I have a structure in my document that appears as follows:
type Document = {
_id: string
title: string
variants: VariantType[]
}
type VariantType = {
timestamp: Int
active: Boolean
content: any[]
}
I am attempting to filter a document using two filter conditions within one query. Initially, I aim to match the _id and then locate a specific variant based on a timestamp.
In my previous query version, I was filtering based on the active
key.
const updatedDocument = await allDocuments
.findOneAndUpdate({ _id: mongoId, 'variants.active': false }, .... };
When I change it to
const updatedDocument = await allDocuments
.findOneAndUpdate({ _id: mongoId, 'variants.timestamp': timestamp }, .... };
it returns a null result.
Is it possible for MongoDB to match a document in this manner? I have come across the $eq
query selector but have struggled to make it work as well.