user4309290
user4309290

Reputation: 5

What am I doing wrong trying to make this run with meteor?

I am trying to adapt the full text search made here to work with meteor. I exported the mongodb url to one running 2.6.1. to make full text search compatible but I am getting these errors server/search.js:2:15: Unexpected token .andserver/search.js:42:7: Unexpected token ). What am I missing?

server.js

Meteor.methods({
    Meteor.ensureIndex("Posts", {
      smaintext: "text"
    }, function(err, indexname) {
      assert.equal(null, err);
    });
  )
};


Meteor.methods({
    feedupdate: function(req) {
      Posts.find({
        "$text": {
          "$search": req
        }
      }, {
        smaintext: 1,
        submitted: 1,
        _id: 1,
        Posts: {
          $meta: "Posts"
        }
      }, {
        sort: {
          textScore: {
            $meta: "posts"
          }
        }
      }).toArray(function(err, items) {
        for (e=0;e<101;e++) {
        Meteor.users.update({
          "_id": this.userId
        }, {
          "$addToSet": {
            "profile.search": item[e]._id
          }
        });
     }
      })
    }
  )
};

Upvotes: 0

Views: 82

Answers (1)

polacekpavel
polacekpavel

Reputation: 423

This is wrong definition of method

Meteor.methods({
Meteor.ensureIndex("Posts", {
  smaintext: "text"
}, function(err, indexname) {
  assert.equal(null, err);
});

) };

you must specify a method name ( http://docs.meteor.com/#/basic/Meteor-methods ) So it will be something like this
Meteor.methods({ myMethodName : function() { Meteor.ensureIndex("Posts", { smaintext: "text" }, function(err, indexname) { assert.equal(null, err); }); } });

in second method there is a semicron and parenthise problem. Correct version is

Meteor.methods({
feedupdate: function(req) {
  Posts.find({
    "$text": {
      "$search": req
    }
  }, {
    smaintext: 1,
    submitted: 1,
    _id: 1,
    Posts: {
      $meta: "Posts"
    }
  }, {
    sort: {
      textScore: {
        $meta: "posts"
      }
    }
  }).toArray(function(err, items) {
    for (e=0;e<101;e++) {
    Meteor.users.update({
      "_id": this.userId
    }, {
      "$addToSet": {
        "profile.search": item[e]._id
      }
    });
 }
  });
}

});

Upvotes: 1

Related Questions