mongo.cr
mongo.cr copied to clipboard
How to find all documents from collection
In ruby mongo driver to find all documents in collection is
collection.find
However, in this driver expect to have some arguments pass to it. Which argument should I pass to find
method in order to get the ideal result ?
@dylandy here is how I did it: https://github.com/sam0x17/crystal-mongo-orm/blob/3262bc6880d7c6ec8e2f756bfc9a1a8050b71bc2/src/mongo_orm/querying.cr#L88
Note that my ORM is able to do this out of the box using the Model.all
method, as you mention.
https://github.com/sam0x17/crystal-mongo-orm
You can get all documents of a collection (as BSON objects) like this:
docs = [] of BSON
collection.find(BSON.new).each do |doc|
docs << doc
end
I don't know if it's the best way, but it works fine.