javascript - Meteor, flow router ssr : findOne returns undefined when called in Meteor.methods from server in a flow-router action -


[edit] problem specific flow router, started issue here : https://github.com/meteorhacks/flow-router/issues/205 not know if actual issue or if conceived wrong way..

when called in server startup code, blog.findone() returns value (server side)

meteor.startup( function () {     console.log( blog.findone() );     // 1 blog post } ); 

but when called in server method call server, returns undefined

meteor.methods( {     gethomedata() {         console.log( blog.findone() );         //undefined 

wtf ?

it's called classic way :

meteor.call( 'gethomedata', ( err, res ) => {     console.log( 'server call err :' + err );     console.log( 'server call res :' + res ); } ); 

same calling code server , client.

i event tried :

let test = () => {     return blog.findone(); };  meteor.startup( function () {     console.log( test() );     // still } );  meteor.methods( {     gethomedata: () => {         console.log( test() );         // still undefined wtf! 

so, here did not understand ?

by way, can insert, update, , remove in method. , undefined whether call client or server. puzzle me...

when method called client side, works.

[ edit ]

i tried unblock , wrapasync (yes, i'm trying anything...)

gethomedata() {     this.unblock();     console.log( 'startcall' );     return meteor.wrapasync( () => {         console.log( 'start async call' );         console.log( blog.findone()._id );         return blog.findone()._id;     } )(); }, 

still working when called client, still returning undifined when called server ( blog.findone() return undefined, call returns error).

the difference can see call client has this.connection , no this.randomseed.

the future way keep working client side, not server side :

future = npm.require( 'fibers/future' ); ... gethomedata( v ) {     this.unblock();     var myfuture = new future();     ( () => {         myfuture.return( blog.findone()._id );     } )();     return myfuture.wait(); }, 


Comments