Getting the ID of document affected by upsert


I am upserting a document like this

       let conversation = {
          contextGraphId: graph.graphId,
          authorGraphId: posting.authorGraphId,
          authorName: posting.authorName,
          authorScreenName: posting.authorScreenName,
          authorThumbnail: posting.authorThumbnail,
          service: posting.service

        let selector = { service: posting.service, authorGraphId: posting.authorGraphId };
        let conversationId = Conversations.upsert(selector, { $set: conversation }); <------------- Offending line
        posting.conversationId = conversationId

Problem is that the Conversations.upsert only returns an ID upon insertion. I also want to retrieve the ID in the case that the document was updated.

Is there any way to accomplish this without resorting to a seperate find query?


I don’t think so (same thing with update).

Unfortunately, as stated in the documentation here, in case of an update, it only send back the number of documents updated by the query. You’ll have to get it with a separate query.