2

How can I get the id when I just saved a nested collection?

Code:

(Topic = schemaname from mongoose)
Topic.findByIdAndUpdate({_id: data.topicId}, {data that im inserting in the nested collection})

The topic is updated and a nested collection is added, also with an id. Is there a way to return the id of the inserted nested collection?

Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
wbbbb
  • 21
  • 2
  • Possible duplicate of [Mongoose: findOneAndUpdate doesn't return updated document](http://stackoverflow.com/questions/32811510/mongoose-findoneandupdate-doesnt-return-updated-document) – Thomas Bormans May 17 '16 at 09:33

1 Answers1

0

try with query option {new:true}

Topicopic.findByIdAndUpdate({_id: data.topicId}, {}, {new:true})
CherryDT
  • 25,571
  • 5
  • 49
  • 74
KibGzr
  • 2,053
  • 14
  • 15