Meteor JS: inconsistency with Meteor JS when dealing with cursors?

I think I may have found a few inconsistencies in Meteor JS. First, this is an example of perfectly acceptable code that does not throw an error in the Meteor JS Template Helper:

Template.admin_menu_items.helpers({
  menuItems: function(){
    console.log('inside menuItems');
    return MenuItems.find();
  },
})

      

However, if I use Session to store the return value MenuItems.find()

eg.

Template.admin_menu_items.rendered = function(){    
  var snapshot = MenuItems.find();
  Session.set('menu_items', snapshot);
}

      

Then use the object stored in sessions in the templating helper:

Template.admin_menu_items.helpers({

      menuItems: function(){
        console.log('inside menuItems');

        //return MenuItems.find();
        return Session.get('menu_items');
      },
 })

      

I am getting the following error:

Exception from Tracker recompute function:
meteor....ddc0aaf (line 888)
Error: {{#each}} currently only accepts arrays, cursors or falsey values.
meteor....ddc0aaf (line 888)

badSequenceError@http://localhost:3000/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:179:1
ObserveSequence.observe/computation</<@http://localhost:3000/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:144:1
Tracker.nonreactive@http://localhost:3000/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:593:12
ObserveSequence.observe/computation<@http://localhost:3000/packages/observe-sequence.js?0532a9dd76dd78f543eb4d79a1e429df186d8bde:121:7
Tracker.Computation.prototype._compute@http://localhost:3000/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:327:5
Tracker.Computation.prototype._recompute@http://localhost:3000/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:346:9
Tracker._runFlush@http://localhost:3000/packages/tracker.js?6d0890939291d9780f7e2607ee3af3e7f98a3d9c:485:9
onGlobalMessage@http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:372:11

      

WHICH DOESN'T MAKE SENSE because I am storing an acceptable return value MenuItems.find()

inside the session and retrieving it .... it should still be the cursor after retrieving ..... right ???

What's the explanation for this ???

To emphasize that using Session to store the value does not alter the object saved on retrieval .... I tried the same code, but only with an array instead of a cursor ... so this is var snapshot = MenuItems.find().fetch();

instead var snapshot = MenuItems.find();

, nor does it throw errors .... ...

+3


source to share


1 answer


Under the hood Session

is the ReactiveDict . If you look at the source , you can see that it serializes its data through EJSON.stringify

.

This works well if you have simple objects and primitives, however, serializing an instance of a class will share all of its methods (functions are not serialized).



This explains why the result of the work fetch

(array of documents) is saved, while the result is find

not saved (cursor instance). Since the cursor methods have been removed, it no longer behaves like a cursor, and spaces will not be able to iterate over their documents.

+4


source







All Articles