Giter Club home page Giter Club logo

Comments (5)

kofrasa avatar kofrasa commented on July 18, 2024

Hi @javiercbk

Thanks for reporting this.

Please can you confirm if you are using the latest version of mingo.

I get the expected output using the latest version 2.0.2.

[
{
   "_id":"59c52580809dd0032d75238a",
   "email":"[email protected]",
   "accounts":[
      {
         "createdAt":"2017-09-22T15:00:17.418Z",
         "updatedAt":"2017-09-22T15:00:17.418Z"
      }
   ],
   "accountInfo":{
      "createdAt":"2017-09-22T15:00:17.418Z",
      "updatedAt":"2017-09-22T15:00:17.418Z"
   }
}
]

from mingo.

javiercbk avatar javiercbk commented on July 18, 2024

Actually you're right. I'm so sorry for wasting your time, it must be an error on my side.

I'm wrapping your library as a mongo driver and I'm trying to add support to $lookup aggregation operation (with the concept of named collection). So I came across with this error yesterday and after a quick debug I thought I pinpointed the error in mingo, but now I can see it is my mistake.

Thanks again

from mingo.

javiercbk avatar javiercbk commented on July 18, 2024

I've found the issue, the problem is the cloneDeep function, it is not cloning the property.

screen shot 2017-09-23 at 6 18 55 pm

To make a quick test, I temporary replaced by lodash cloneDeep implementation

screen shot 2017-09-23 at 6 20 40 pm

The problem is that the function each does not pickup the property

from mingo.

javiercbk avatar javiercbk commented on July 18, 2024

Pinpointed the issue, when an object has a boolean property with false value, cloneDeep will break and stop cloning properties.

const chai = require('chai');
require('mocha');
const { Aggregator } = require('mingo');

const { expect } = chai;

describe('cloneDeep bug', () => {
  it('should cloneDeep object with false property', () => {
    const oper = [{
      $addFields: {
        accountInfo: {
          $arrayElemAt: ['$accounts', 0],
        },
      },
    }];
    const col = [{
      _id: '59c52580809dd0032d75238a',
      email: '[email protected]',
      deleted: false,
      accounts: [{
        createdAt: '2017-09-22T15:00:17.418Z',
        updatedAt: '2017-09-22T15:00:17.418Z',
      }],
    }];
    const expected = [{
      _id: '59c52580809dd0032d75238a',
      email: '[email protected]',
      deleted: false,
      accountInfo: {
        createdAt: '2017-09-22T15:00:17.418Z',
        updatedAt: '2017-09-22T15:00:17.418Z',
      },
      accounts: [{
        createdAt: '2017-09-22T15:00:17.418Z',
        updatedAt: '2017-09-22T15:00:17.418Z',
      }],
    }];
    const aggregatedCollection = new Aggregator(oper).run(col);
    expect(expected).to.deep.equal(aggregatedCollection);
  });
});

from mingo.

kofrasa avatar kofrasa commented on July 18, 2024

I think I have spotted the bug. This is coming from a function depended on by the cloneDeep implementation. Will fix soon

from mingo.

Related Issues (20)

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.