Can we set cursor as a session variable?

后端 未结 2 412
轻奢々
轻奢々 2021-01-12 23:01

I tried to set a cursor as a session variable looks like it is not working.

Anyone has idea about it ??

My Code:

 Meteor.call(\'apiresult\',f         


        
相关标签:
2条回答
  • 2021-01-12 23:12

    Cursors can actually be stored in Session... sometimes. open the leaderboard app and try this in the browser console:

    > Session.set('mycursor', Players.find());
    undefined
    > Session.get('mycursor')
    LocalCollection.Cursor {collection: LocalCollection, selector_f: function, sort_f: null, skip: undefined, limit: undefined…}
    > Session.get('mycursor').fetch()
    [Object, Object, Object, Object, Object]

    Now download the code of the leaderboard example app, use the latest Meteor, and do the same thing in the browser console. You might get:

    enter image description here

    The moral of the story seems to be, don't store cursors in session variables. Store the Minimongo selector and options (sort, fields etc.) instead as objects.

    0 讨论(0)
  • 2021-01-12 23:13

    Interesting thought. It would not be required though, because a cursor is already reactive. You can store the cursor in an ordinary variable.

    One thing to point out though is you can't send cursors down using Meteor.call, you can send down javascript objects or specify your own EJSON but you couldn't do this with cursors.

    So you can store cursors in global variables if you do the .find() locally, but you cant do it on the server then transfer the cursor using Meteor.call

    You can use a publish/subscribe function for this instead.

    0 讨论(0)
提交回复
热议问题