sql >> Base de Datos >  >> NoSQL >> MongoDB

¿Cómo filtrar documentos basados ​​en una matriz incrustada?

Debe usar $elemMatch(projection) . Algo como lo siguiente debería funcionar.

import static com.mongodb.client.model.Projections.elemMatch;

Bson filters = and(eq("userId", userId));
Bson projections = fields(elemMatch(ARRAY_FIELD_NAME, eq("id", id)), excludeId());