garima
garima

Reputation: 5244

Unable to invoke Meteor Call function

SERVER

if (Meteor.isServer) {
          Meteor.startup(function () {
            // code to run on server at startup


          }

    Meteor.methods({
        getApiResult: function() {
            try {
                var pipeline = [{$match: {"ACTIVE": 1}}, {"$group": {"_id": "$VARIENTS.NAME"}}, {
                    "$project": {
                        "_id": 0,
                        "TEMPLATE_NAME": "$_id"
                    }
                }];

                console.log("display pipeline");
                console.log(pipeline);
                var result = nodeDB.aggregate(pipeline);

                console.log("display result", result);

                for (i = 0; i < result.length; i++) {
                    var Temp_Name = result[i];
                    console.log("temp name is ", Temp_Name);
                    //productDB.insert({ Temp_Name: $(". Temp_Name").val()});
                    return result;

                }
            }catch (_error) {
                return false;
            }

        });

    }
    }

CLIENT

if (Meteor.isClient) {
  //error here   **Meteor.call**('getApiResult', function(err, result) {
          if (result) {
              console.log("reached meteor call")
              console.log(result);
          }
      });
};

ERROR: Unexpected identifier at the line marked

Upvotes: 0

Views: 104

Answers (2)

kodamirmo
kodamirmo

Reputation: 90

You have a lot of problems with the sintaxis!

Server

if (Meteor.isServer) {

    Meteor.startup(function () {

    });

    Meteor.methods({

        getApiResult: function() {

           try {
            var pipeline = [{$match: {"ACTIVE": 1}}, {"$group": {"_id": "$VARIENTS.NAME"}}, {
                "$project": {
                    "_id": 0,
                    "TEMPLATE_NAME": "$_id"
                }
            }];

            console.log("display pipeline");
            console.log(pipeline);
            var result = nodeDB.aggregate(pipeline);

            console.log("display result", result);

            for (i = 0; i < result.length; i++) {
                var Temp_Name = result[i];
                console.log("temp name is ", Temp_Name);
                //productDB.insert({ Temp_Name: $(". Temp_Name").val()});
                return result;

            }

        }catch (_error) {
            return false;
        }


      }

    });

}

Client

if (Meteor.isClient) {
   Meteor.call('getApiResult', function(err, result) {
      if (result) {
          console.log("reached meteor call")
          console.log(result);
      }
   });
};

Upvotes: 1

yasaricli
yasaricli

Reputation: 2533

if (Meteor.isClient) {
  //error here   **Meteor.call**('getApiResult', function(err, result) {
      if (result) {
          console.log("reached meteor call")
          console.log(result);
      }
  // }); // remove line Meteor.call end 
};

remove Meteor.call end });

Upvotes: 1

Related Questions