【问题标题】:What am I doing wrong trying to make this run with meteor?试图用流星运行这个我做错了什么?
【发布时间】:2014-12-16 13:25:40
【问题描述】:

我正在尝试调整 here 的全文搜索以与流星一起使用。我将 mongodb url 导出到运行 2.6.1 的一个。使全文搜索兼容,但我收到这些错误server/search.js:2:15: Unexpected token .andserver/search.js:42:7: Unexpected token )。我错过了什么?

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
          }
        });
     }
      })
    }
  )
};

【问题讨论】:

    标签: node.js mongodb search meteor mongodb-query


    【解决方案1】:

    这是错误的方法定义

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

    ) };

    您必须指定方法名称 (http://docs.meteor.com/#/basic/Meteor-methods) 所以会是这样的
    Meteor.methods({ myMethodName : function() { 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
          }
        });
     }
      });
    }
    

    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 2015-02-25
      相关资源
      最近更新 更多