KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to query in Mongo collection ? #388

Open Sourabh Jain opened this topic on on Jul 24, 2018 - 2 comments

Sourabh Jain commented on Jul 24, 2018

How to query the below data -

{

"_id" : "0005b9cb-bdea-4a0e-a73e-58a87fa5502f",
"book" : {
    "$ref" : "book",
    "$id" : "530"
},
"groupddetails" : [ 
    {
        "$ref" : "group",
        "$id" : "1017"
    }, 
    {
        "$ref" : "group",
        "$id" : "1016"
    }
],
"isCourseBook" : false,
"isSample" : false,
"subscriptionDetailsList" : [ 
    {
        "_id" : "fcf944d5-2134-4a14-8a9a-9f8725fcf73e",
        "subscriptionType" : "organization",
        "activationDate" : ISODate("2015-08-24T18:31:00.000Z"),
        "expiryDate" : ISODate("2016-02-19T18:29:00.000Z"),
        "accessCode" : "dec81577-9736-4f0b-98c2-7b710a991979",
        "isSample" : false
    }
],
"user" : {
    "$ref" : "user",
    "$id" : "384eb921-683a-4cff-b837-cf4187db1299"
}

}

I want subscriptionType = 'organization'.
How can i filter out that data ?

---------------------------------------------------------------------------------------------------------------
Also, how can i get single column from the mongo collection? Please see below - 
$this->src('ops')
        ->query(array("collection"=>"user_book_purchase"))
        ->pipe(new Filter(array(
            array("subscriptionDetailsList","!=", NULL)
        )))
        ->pipe(new Group(array(
                    "by"=>"_id",
                    "count"=>"cntval"
        )))
        ->pipe(new Group(array(
            "sum"=>"cntval"
        )))
        ->pipe($this->dataStore('subscription_sold'));

I want a single column from collection.
David Winterburn commented on Jul 25, 2018

Hi Sourabh Jain,

For filtering please try the following command:

->query(array(
    "collection"=>"user_book_purchase",
    "find" => array(
        "subscriptionDetailsList" => array(
            "subscriptionType" => "organization"
        )
    )
))

To select single field or certain fields from Mongo please check this doc and apply to the "find" param: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/

Let us know if you need further info. Thanks!

Sourabh Jain commented on Jul 25, 2018

Thank you so much :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None