Retrieve MySQL insert id in Meteor method
NickName:CoastalP47 Ask DateTime:2015-02-11T06:56:02

Retrieve MySQL insert id in Meteor method

I am relatively new to Node and Meteor and am trying to retrieve the insert ID of a MySQL query using the numtal:mysql package. The trouble I run into is the query function running on the server and not returning to the client. I need the ID to return to the client so I can route the client to the newly created entry.

Client:

Template.new.events({
  'click .button.submit' : function(){
    Meteor.call('demoFunc', function(error, result){
      console.log(result);
    });
  },
});

Server:

Meteor.methods({
  demoFunc:function(){
    //construct deal object
    var newDeal = {
      dealer_id : 1,
      client_id : 1
    };

    //deal query
    liveDb.db.query('INSERT INTO deal SET ?', newDeal, function(err, result){
      return result.returnId;
    });
  }

});

If I could get the result.returnId in the demoFunc method to return to the client then I would be golden. If anyone's run into anything like this or worked around this, any help would be greatly appreciated.

Copyright Notice:Content Author:「CoastalP47」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28443490/retrieve-mysql-insert-id-in-meteor-method

Answers
Mário 2015-02-11T02:32:02

The best place to ask that is at https://github.com/numtel/meteor-mysql/issues\n\nThis is a community packages and I highly recommend not to use it in production, only for learning/fun. You can also contribute to this repo by adding that feature that you want.\n\nIt is expect that Meteor will support MySQL soon. Meteor bought Fatomdb: http://techcrunch.com/2014/10/07/meteor-acquires-yc-alum-fathomdb-for-its-web-development-platform/",


More about “Retrieve MySQL insert id in Meteor method” related questions

Retrieve MySQL insert id in Meteor method

I am relatively new to Node and Meteor and am trying to retrieve the insert ID of a MySQL query using the numtal:mysql package. The trouble I run into is the query function running on the server an...

Show Detail

Retrieve _id after insert in a Meteor.method call

I need to retrieve the _id after insert a document. In client: Meteor.call('saveDocument', value1, value2); In server saveDocument: function (value1, value2) { MyCollection.insert({ 'value1':

Show Detail

Use id from collection insert within a meteor method

Within my Angular / Meteor app I want to use the created id from a collection insert in a meteor method in the client. Within a client Angular component the following method exists. onSubmit(): v...

Show Detail

Unable to retrieve _id after insert in a Meteor.method call

I can't get the return value of the inserted _id using the answers that I found on the same question here like this; Meteor.call('saveDocument', value1, value2, function(error, result){ var

Show Detail

Return _id to client on insert in Meteor

Whats the best way to retrieve the _id of the data thats JUST been inserted into a collection to the client. I'm trying to redirect on submit with FlowRouter.go("/:_id") but there is no way of retr...

Show Detail

Meteor: How can I retrieve the inserted _id inside a method?

I have a meteor method to insert a document. The id for that document serves as a url extension. After the document is created, I also send an email via the same method. In the email, I want to inc...

Show Detail

Setting unique id with Meteor insert

I'm linking the FB Graph API to Meteor so that I can retrieve a users photos and I'm having trouble setting the Meteor id to the Facebook id for each photo. Right now when the function is called it...

Show Detail

Meteor: insert failed: Method not found

I am receiving the insert failed: Method not found log message and it probably is the result of what is described in these threads: Meteor using a local connection results in error: insert failed:...

Show Detail

mysql_insert_id() failed to retrieve auto increment ID

$dml = "insert into ... "; mysql_query($dml,$con); $Id = isset($row) ? $row['id'] : mysql_insert_id($con); I saw the record is created,but just can't retrieve the Id. What's wrong? EDIT

Show Detail

Retrieve insert id in stored procedure with mysql

I have stored procedure for insert booking record with details like booking_id, name, r_id, t_id etc. Now I want to know how to retrieve insert id of this record. Stored procedure allow LAST_INS...

Show Detail