Get _id of an newly inserted Item
sosnet opened this issue · comments
Hey, I'm not able to get out the _id after I insert a new item to my meteor-db.
My code looks like this:
Server:
newItem() {
if (!this.userId)
throw new Meteor.Error('unauthorized', 'User must be logged-in to insert an item');
return Items.insert({ ownerId: this.userId, title: 'New Item' });
}
Client:
MeteorObservable.call('newItem').subscribe({
next: () => {
//get _id
},
error: (e: Error) => {
console.log("Error: " + e);
}
});
Can you please tell me how to get the _id
?
I also posted here: http://stackoverflow.com/questions/41040730/ionic2-meteor-get-id-of-new-inserted-item
Ok, error was on the server-side. Items.collection.insert(...) is correct. So not a problem of MeteorObservable, sorry.