Hey, I’m in an Ionic2/Angular2 project and I’m using a meteor-server and it’s working quite fine. But now I would need the newly generated _id for my last inserted item to forward my app to the new item’s page after the insert.
On the server I’m doing an insert inside its method-calls:
Meteor.methods({
newSpot() {
return Spots.insert({ ownerId: this.userId, title: 'New Spot' });
}
...
I call this on my client like this (got this lines from the tutorial):
newSpot() {
MeteorObservable.call('newSpot').subscribe({
next: () => {
//get _id here
},
error: (e: Error) => {
console.log("Error: " + e);
}
});
}
I found lot of answers to the same question, but it looks like that older versions returns just the _id-string on the insert, but now it returns an Observable and all answers refer to the old versions.
On the server I’m able to get the _id out of the Observable, so I’ve tried to only return the _id-string, but this also didn’t work. I’m not able to get out any data on the client side.
If there is any other way I should do the call on the client or if the call is fine to get the _id with it, please let me know how. Thank you so much!
Edit: I also posted it here: http://stackoverflow.com/questions/41040730/ionic2-meteor-get-id-of-new-inserted-item