I am making this work with meteor exporting mongodb to a 2.6.6 separate database and send the results to a array to get published. It is returning this error. How can it be fixed?
I20141224-16:55:52.410(-5)? Exception while invoking method 'ftsearch' TypeError: Object [object Object] has no method 'toArray'
I20141224-16:55:52.629(-5)? at [object Object].Meteor.methods.ftsearch (app/server/search.js:20:6)
server/search.js
Meteor.methods({
ftSearch: function(req) {
Posts.find({
"$text": {
"$search": req
}
}, {
posttext: 1,
submitted: 1,
_id: 1,
Posts: {
$meta: "posts"
}
}, {
sort: {
textScore: {
$meta: "posts"
}
}
}).toArray(function(err, items) {
Meteor.users.update({
"_id": this.userId
}, {
"$addToSet": {
"profile.search": foreach(items)
}
});
});
function foreach(idems) {
result = "id";
idems.forEach(function(idem) {
result = idem._id;
});
return result;
}
}
});
collections/posts
Posts = new Meteor.Collection('posts');//...
var post = _.extend(_.pick(postAttributes, 'title', 'posttext'), {
userId: user._id,
username: user.username,
submitted: new Date().getTime(),
commentsCount: 0,
upvoters: [], votes: 0,
});
Meteor.ensureIndex("posts", {
posttext: "text"
}, function(err, indexname) {
assert.equal(null, err);
});
var postId = Posts.insert(post);
return postId;
},
Aucun commentaire:
Enregistrer un commentaire