"Query the collection and return the documents that match with filter"
(let ((table (get-table col)))
(vhash-fold
- (lambda (key value result) (cons (vhash->alist value) result))
+ (lambda (key document result)
+ (cond ((match-document? document filter)
+ (cons (vhash->alist document) result))
+ (else
+ result)))
'()
table)))
+(define (match-document? document filter)
+ "Try to match the given document with a list of conditions"
+ (cond ((null? filter)
+ #t)
+ (else
+ (and
+ (equal? (vhash-assoc (caar filter) document) (car filter))
+ (match-document? document (cdr filter))))))
+
;;; Tools
; Search
(test-eqv 2 (length (find col '((a . 1)))))
+(test-eqv 1 (length (find col '((a . 1) (b . 2)))))
+(test-eqv 0 (length (find col '((a . "test")))))
(test-end "bongodb")