Giter Club home page Giter Club logo

json-aggregate's People

Contributors

dependabot[bot] avatar salvadr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

json-aggregate's Issues

Support functions wherever string paths are supported

Feature request:

[{ company: "a", employeeCount: 45, category: 1, product: "Product A", price: 120 },
{ company: "a", employeeCount: 45, category: 1, product: "Product B", price: 80 },
{ company: "a", employeeCount: 45, category: 2, product: "Product C", price: 105 },
{ company: "a", employeeCount: 45, category: 2, product: "Product D", price: 95 },
{ company: "b", employeeCount: 30, category: 1, product: "Product A", price: 40 },
{ company: "b", employeeCount: 30, category: 1, product: "Product B", price: 100 },
{ company: "b", employeeCount: 30, category: 2, product: "Product C", price: 60 },
{ company: "b", employeeCount: 30, category: 2, product: "Product D", price: 130 }] 
collection.group({
 id: (c) => c.company.toUpperCase(),
 lowestPrice: { $min: (c) => c.price * 2}
})
.exec() 

output

[{ id: 'A', lowestPrice: 160 },
{ id: 'B', lowestPrice: 80 }] 

GROUP method with JSON Numbers

Thanks for you project!

I was wondering if you had any idea on how to make it possible to use the "group" method with Numbers? I've attached an example here so the goal would be to perform SUM based on the "actor_id" attribute. Here, the result would be 3.

                      groupBysum() {

                        const jsonAggregate = require('json-aggregate')
                        const arr = [
                        {
                        	"actor_id": 1,
                        	"film_id": 1,
                        	"last_update": "2006-02-15 05:05:03"
                        }, {
                        	"actor_id": 1,
                        	"film_id": 23,
                        	"last_update": "2006-02-15 05:05:03"
                        }, {
                        	"actor_id": 1,
                        	"film_id": 25,
                        	"last_update": "2006-02-15 05:05:03"
                        } ]

                        const collection = jsonAggregate.create(JSON.stringify(arr))
                        
                        collection.group({ id: 'actor_id', count: { $sum: 1 }})
                        
                        console.log('Result=',collection);

                      }

This gives the following error: TypeError: Cannot read property 'data' of undefined. It works fine with "last_update" instead of "actor_id".

nested oject unwind or group

i have below object...

var myJsonData=
    [
    { company: "e", employeeCount: 45,
        scoreRange:[
        {value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:3}]},
        {value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:4}]},
        {value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:7}]},
        {value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:8}]},
        ] },

        { company: "a", employeeCount: 45, scoreRange:[
            {value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
            {value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
        ] },

        { company: "b", employeeCount: 45, scoreRange:[
            {value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
            {value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
        ] },
        { company: "c", employeeCount: 45, scoreRange:[
            {value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
            {value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
            {value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
        ] },
    ];

i want to unwind by exception array...

    collection
     .unwind("scoreRange")
     .unwind("scoreRange.exception")
     .exec();

but it doesnt work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.