-1

I am wondering how I can check if an entry exists in mongodb. example :

I have this schema :

const AuthorSchema = new Schema({
    name : { type : String,  required : true},
    books: [BookSchema]
});

If the Author i am trying to add already exists I would like to still add the book to the existing author , but I dont want to create a duplicate of author.

Pseudo code is fine, as long as I get the Idea of the flow. Any posts or blog articles are fine as long as they describe the problem i am having.

Kevin.a
  • 4,094
  • 8
  • 46
  • 82
  • 1
    Did you take a look at [upsert command](https://docs.mongodb.com/manual/reference/method/Bulk.find.upsert/index.html) already? – gmauch Mar 25 '20 at 13:05