randomDocument method
Implementation
Map<String, dynamic>? randomDocument(Map<String, dynamic> query) {
final matchingDocuments = find(query);
if (matchingDocuments.isEmpty) {
return null;
}
final List<Map<String, dynamic>> matchedDocuments = matchingDocuments
.where((document) => _matchWithOperators(document, query))
.toList();
if (matchedDocuments.isEmpty) {
return null;
}
final randomIndex = Random().nextInt(matchedDocuments.length);
return matchedDocuments[randomIndex];
}