Hi!
 Before I get into the reason for the post, I just want to say that I have been 
looking a several languages for a winter project, and Racket is definitely one 
of the best in terms of stability, documentation and tools. I'm old enough to 
have used "vi" before "vim" was even around, and over the intervening years 
(decades!), I have not been sure that graphical IDEs actually improved my 
efficiency, but I really like DrRacket! And, at least so far, "raco" has worked 
like a charm. Last winter's project language (to remain unnamed) had an 
equivalent to "raco" that made me want to scream. So ... kudos to the 
Racketeers!

Now on to MongoDB. I began playing with Racket MongoDB "Quickstart" example. It 
went well so I changed a few things, and I checked everything through the mongo 
shell. Then I began to play around with more Racket commands, and 
"mongo-db-collections" always returned an empty list, even when the mongo 
shell's "show collections" command returned a (correct) non-empty list. I 
finally tracked the problem down to a change in the MongoDB API since version 
3.0 (my MongoDB is 3.4).

Instead of "<database>.system.namespaces" they now use "listCollections". So I 
first tried to change "~a.system.namespaces" to "listCollections" in (a copy of 
) "... mongodb/basic/driver.rkt" without success. Then I noticed that the 
"mongo-list-databases" command used a "listDatabases" call to MongoDB. Thinking 
there might be a reason for the similar names, I tried modeling a new 
"mongo-db-collections" after "mongo-list-databases". After much wailing and 
gnashing of teeth (and learning some Racket in the process) I came up with what 
I hope is a suitable fix:

(provide/contract
 [mongo-db-collections (mongo-db? . -> . (listof string?))])
(define (mongo-db-collections d)
  (for/list ([c (in-vector (mongo-list-collections d))] #:when (hash-has-key? c 
'idIndex))
    (hash-ref c 'name)))

The "#:when" clause is because MongoDB slipped a "system.profile" collection 
into the response. It is distinguished from the ones for the database I was 
asking about by not having an 'idIndex field.

... and the helper function:

(define (mongo-list-collections d)
  (hash-ref (hash-ref (mongo-db-execute-command! d `([listCollections . 1]))
            'cursor) 'firstBatch))

The two "hash-ref"s are to peel the desired info out of the json (bson) 
returned by MongoDB.

I'm working on some routines to search the MongoDB and pretty-print the results 
of the search, but they are not very robust right now. If anyone is interested, 
or has more mature code for these tasks, let me know.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to