Hi Corina,
The $not
operator does not support operations with the $regex
operator. Although you can use the $not operator along with //
to express a not filter match.
For example to find an item value that does not start with the word ‘baco’ in MongoDB Shell:
db.collection.find( { item: { $not: /^baco/ } } );
You can achieve a similar operation in C# using FilterDefinition, for example:
/* Create a regex filter for 'text' field not starting with 'friday'*/
FilterDefinition<BsonDocument> filter = "{text: {$not: /^friday/ }}";
var collectionFilter = collection.Find(filter);
var result = await collectionFilter.ToListAsync();
foreach (BsonDocument doc in result)
{
Console.WriteLine(doc.ToString());
}
The example snippet above is written in:
See Definitions and Builders for more information.
Regards,
Wan.