MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Trovare elemento array per valore campo nel driver MongoDB C#

Usa ElemMatch per trovare documenti il cui array contiene un elemento che corrisponde a una condizione su campo.

var filter = Builders<Post>.Filter.ElemMatch(
  x => x.Tags,
  x => x.Name == "test"
);
var res = await collection.Find(filter).ToListAsync();

Questo abbina post in cui l’array Tags ha un elemento con Name uguale a "test".