Tôi cần truy xuất _id sau khi chèn tài liệu.Truy xuất _id sau khi chèn vào lệnh gọi Meteor.method
Trong client:
Meteor.call('saveDocument', value1, value2);
Trong máy chủ
saveDocument: function (value1, value2) {
MyCollection.insert({ 'value1': value1, 'value2': value2});
}
Tôi đã thử với các hàm callback của chèn ở phía máy chủ. Bằng cách này, tôi có thể nhận _id của tài liệu, nhưng bên trong hàm callback và điều này không thể trở về cuộc gọi của khách hàng:
saveDocument: function (value1, value2) {
MyCollection.insert({ 'value1': value1, 'valu2': value2},
function(err, docsInserted){ console.log(docsInserted) });
//Works, but docsInserted can't return to the client.
}
Tôi đã phải rite nó như thế cho nó hoạt động: 'saveDocument: function (value1, value2) { var newDoc = MyCollection.insert ({'value1': value1, 'valu2': value2}); return newDoc; } ' – eloone
Tuyệt vời, cảm ơn bạn. Lời giải thích tuyệt vời. – Andy