louismullie/treat

Using MongoDb

Closed this issue · 2 comments

I have seen in the documentation about connecting to mongodb .. but there are no examples on how we can use the mongodb documents

See the following sections from the manual.

To retrieve a document from MongoDB:

        # If a hash is provided, that hash will be used as
        # a selector to retrieve a document from the DB.
        # This can be done based on the ID of the document:
        d = document({id: 103757301323})

        # Or through any given feature of a certain document:
        d = document({'features.file' => 'somefile.txt'})

        # N.B. Currently, MongoDB is the only supported DB.
        # You need to configure the database adapter before
        # using this particular way of retrieving documents.

To retrieve a collection from MongoDB:

        # If a hash is passed to the builder, that hash
        # will be used as a selector to retrieve documents
        # from the DB, and a collection containing these 
        # documents will be loaded. An empty hash loads 
        # all documents in the DB:
        c = collection({})

        # You can also use any arbitrary feature that 
        # you have defined on the documents to create 
        # a collection on-the-fly:
        c = collection({'features.topic' => 'news'})

        # N.B. Currently, MongoDB is the only supported DB.
        # You need to configure the database adapter before
        # using this particular way of creating collections.

I hope this solves your problem. Let me know if you have any further questions.

Thanks! i did read this in the documentation.

How do i make a collection from a single table?