How to insert in Collection within a Fiber ?

1,161 views
Skip to first unread message

Arthur Battut

unread,
Mar 19, 2014, 12:24:00 PM3/19/14
to meteo...@googlegroups.com
Hello,

I want to insert in the Tweets collection every tweets from the stream made with Twit (npm module), inside a method.

Here is my code:

    stream: function(hashtag) {
        //Création du stream
        stream = T.stream('statuses/filter', { track: hashtag });
        var currentHashtag = hashtag;

        // Lance le stream
        stream.on('tweet', function (tweet) {
             var userName = tweet.user.screen_name;
                var userTweet = tweet.text;
                var tweetDate = tweet.created_at;
                var profileImg = tweet.user.profile_image_url;

            console.log(userName+" a tweeté: "+userTweet+" le: "+tweetDate);
            console.log("=======================");

            Tweets.insert({user: userName, tweet: userTweet, picture: profileImg, date: tweetDate, hashtag: currentHashtag}, function(error) {
                if(error)
                    console.log(error);
            });
        });
    }


And here is my error message:
[Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor Libraries with Meteor.bindEnvironment. ]


I've tried different solutions in vain, like wrap the Collection insertion in a Fiber(), and I try to use a Meteor.bindEnvironment, but never understand how to properly use it.

Can you help me ?

Gadi Cohen

unread,
Mar 19, 2014, 2:56:29 PM3/19/14
to meteo...@googlegroups.com
stream.on('tweet', Meteor.bindEnvironment(function(tweet) {
   ...
}));

:)

Arthur Battut

unread,
Mar 19, 2014, 3:16:24 PM3/19/14
to meteo...@googlegroups.com
Thanks for your answer, I don't have errors now (wich is great), but when I go into meteor mongo and make db.Tweets.find().count(), it returns 0. Do you know why ?

Gadi Cohen

unread,
Mar 20, 2014, 12:47:59 AM3/20/14
to meteo...@googlegroups.com
Mmm, no :)  Are the tweets arriving and showing up in the server console log?  Is there a 2nd result argument to the Insert callback?

Gadi Cohen

unread,
Mar 20, 2014, 2:59:44 AM3/20/14
to meteo...@googlegroups.com

can you show me the line where you instantiate the Tweets Collection?

--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/pUCJVZ8GUR0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arthur Battut

unread,
Mar 20, 2014, 6:28:50 AM3/20/14
to meteo...@googlegroups.com
I fix the problem last night. It was just about autopublish, and subscribtion ^^
--
Arthur BATTUT
Reply all
Reply to author
Forward
0 new messages