Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property '_str' of undefined #26

Open
ThusStyles opened this issue May 31, 2015 · 6 comments
Open

Cannot read property '_str' of undefined #26

ThusStyles opened this issue May 31, 2015 · 6 comments

Comments

@ThusStyles
Copy link

Getting strange random error, not sure exactly how to solve, search still works but stay loading forever and seems to cause cpu/memory leaks.

Exception in delivering result of invoking 'search.source': TypeError: Cannot read property 'str' of undefined
at http://localhost:3000/packages/meteorhacks_search-source.js?b3122033999151d35259310e0ffa257e17669508:125:25
at Array.forEach (native)
at Function.
.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
at SearchSource._updateStore (http://localhost:3000/packages/meteorhacks_search-source.js?b3122033999151d35259310e0ffa257e17669508:123:5)
at handleData (http://localhost:3000/packages/meteorhacks_search-source.js?b3122033999151d35259310e0ffa257e17669508:89:14)
at Meteor.bindEnvironment as _callback
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3860:12)
at _.extend.receiveResult (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3880:10)
at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4970:9)
at onMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:12)

@arunoda
Copy link
Member

arunoda commented Jun 1, 2015

Seems like you are not sending _id for each documents from server.

@ThusStyles
Copy link
Author

I am sending them, if I do a console log of the data returned in the search source method then it shows documents with an _id field

@lorensr
Copy link

lorensr commented Jun 5, 2015

I had this problem. Transporter was converting _id to id, so I fixed it by copying id to _id before returning the data in SearchSource.defineSource.

@biofractal
Copy link

I had exactly this problem whilst following along with the bulletproofmeteor Building a Real-World Search App – Meteor Package Search tutorial. @lorensr 's reply above gave me the hint I needed but it didn't quite fit what I was seeing so here is my fix.

In your SearchSource.defineSource there may well be a map function similar to this:

_Before_

var data = result.hits.hits.map(function(doc) {
    var source = _.clone(doc._source);
    source._score = doc._score;
    return source;
});

The problem is that this map does not include the _id in the source. So you need to update it to this:

_After_

var data = result.hits.hits.map(function(doc) {
    var source = _.clone(doc._source);
    source._score = doc._score;
    source._id = doc._id; // <- add this line
    return source;
});

Once you include the _id into the source then the SearchSource error goes away and all is well.

@davegariepy
Copy link

Thanks @biofractal, that fixed it for me!

@derekclair
Copy link

Thanks @biofractal! I as well had the same issue, fixed me right up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants