appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
481 stars 27 forks source link

When using "mutations" with a subscription it's throwing a warning #207

Closed diogomartino closed 1 year ago

diogomartino commented 1 year ago

Hi! First of all, thanks for your work, this lib is awesome. I'm using NodeJS v18.7.0 with AceBase 1.27.0.

I'm trying to execute something when some specific props of an object change, and I'm trying to use subscriptions for this. But, while using code from the documentation, it's throwing a warning in the console:

  db.ref(`messages/${message.id}`).on('mutations', (snapshots) => {
    snapshots.forEach((snapshot) => {
      console.log('snapshot', snapshot.val());
    });
  });

It's throwing: Unless you know what you are doing, it is best not to use the value of a mutations snapshot directly. Use child methods and forEach to iterate the mutations instead

What am I doing wrong? The lack of examples when using the "mutations" is making me quite confused, if that part could be improved it would be great.

Thanks!

appy-one commented 1 year ago

Hi @diogomartino, thanks for reporting this. Kindly note that it is NOT throwing anything, it only logs a warning message to the console. In your case, it should not do this (you are using forEach so that should be good). I checked the code and think I found the issue, I'll fix it asap!

diogomartino commented 1 year ago

Oh yes, I meant throwing as like a logging term, not like throwing an exception, you are correct. Thanks for seeing this 👍

appy-one commented 1 year ago

@diogomartino I fixed this in acebase-core v1.26.1, I'll publish a new acebase package shortly

appy-one commented 1 year ago

@diogomartino Fix has been published in https://github.com/appy-one/acebase/releases/tag/v1.28.0

Sponsor AceBase Spread the word contribute

diogomartino commented 1 year ago

Thank you🙏