tunguska-reactive-aggregate icon indicating copy to clipboard operation
tunguska-reactive-aggregate copied to clipboard

Accounting for if docs exist before calling 'dataByKey'

Open smohanty92 opened this issue 2 years ago • 5 comments

smohanty92 avatar Jun 27 '22 15:06 smohanty92

I tested this out, but got hit with another exception: "Cannot read property 'dataByKey' of undefined"

jdalrymple avatar Aug 09 '22 13:08 jdalrymple

@jdalrymple Thanks for testing! Any chance you can share the code you're using so that I can reproduce and be able to debug more.

smohanty92 avatar Aug 09 '22 14:08 smohanty92

Having the same issue in a complex setup with NO_MERGE publications strategy and publishing to client-only collection.

Exception in changedobserveChanges callback: [
  Cannot read property 'documents' of undefined
    packages/tunguska:reactive-aggregate/aggregate.js 282:13
    packages/tunguska:reactive-aggregate/aggregate.js 301:7
    packages/tunguska:reactive-aggregate/aggregate.js 323:9
    packages/meteor.js 1417:24
    packages/meteor.js 1430:14
    packages/mongo/observe_multiplex.js 178:30
    packages/underscore.js 139:11
    packages/mongo/observe_multiplex.js 172:9
    packages/meteor.js 994:16
    packages/meteor.js 971:12
] {
  path: '',
  sanitizedError: [
    tunguska:reactive-aggregate [Error]
      packages/tunguska:reactive-aggregate/aggregate.js 11:27
      packages/meteor.js 692:17
      packages/tunguska:reactive-aggregate/aggregate.js 282:13
      packages/tunguska:reactive-aggregate/aggregate.js 301:7
      packages/tunguska:reactive-aggregate/aggregate.js 323:9
      packages/meteor.js 1417:24
      packages/meteor.js 1430:14
      packages/mongo/observe_multiplex.js 178:30
      packages/underscore.js 139:11
      packages/mongo/observe_multiplex.js 172:9
      packages/meteor.js 994:16
      packages/meteor.js 971:12
  ] {
    isClientSafe: true,
    error: 'Error',
    reason: 'tunguska:reactive-aggregate',
    details: undefined,
    message: 'tunguska:reactive-aggregate [Error]',
    errorType: 'Meteor.Error'
  },
  errorType: 'tunguska:reactive-aggregate'
}

It is almost solved by this PR, BUT need also to add question mark after get(localOptions.clientCollection):

            const previousDocs = sub._session.collectionViews.get(localOptions.clientCollection)?.documents;
            const previousFields = [previousDocs && previousDocs.get(doc_id).dataByKey.keys()];

vbgm avatar Feb 05 '24 11:02 vbgm

@robfallows can't you just add the two lines of code yourself? :-) it will be faster than making this PR stuff OR waiting for @smohanty92 to react. Come on, efficiency over processes! :-)

vbgm avatar Feb 05 '24 13:02 vbgm

@robfallows Here it is: https://github.com/robfallows/tunguska-reactive-aggregate/pull/79 So that I get rid of my customised version of this wonderful package :-)

vbgm avatar Feb 05 '24 14:02 vbgm