title: synchronise mongoose and nodejs operation
body: <p>As a part of bootcamp course I am going through, I am learning building restful API's along with Mongoose, GraphQL and NodeJs.</p>
  
  <p>Here is my code </p>
  
  <pre><code>resolve (parent, args) {
  
                  let books = new book({
                      name: args.name, 
                      genre: args.genre,
                      authorName: args.authorName
                  })    
  
                  let author = new Author({ 
                      name: args.authorName
                  })
  
                  book.find( 
                      {
                          name: args.name
                      }, function(error, results) {
                          if (results.length == 0 ) {
                              Author.find(
                                  {
                                    name: args.authorName
                                  },
                                  function (err, result) {
                                      if (result.length == 0) {    
                                      author.save()
                                    }
                                   })
                                }
                                books.save()  
                              })
                      return books
              }
  </code></pre>
  
  <p>Now, While this works, the problem is that books and author are linked together in GraphQL query and when running the query. </p>
  
  <p>Putting aside the entire story part. I want to return books (or let's say I want to do return books.save()) when the operation in my mongoose is over (since mongoose is async) </p>
  
  <p>I stupidly thought about doing something like this in the end </p>
  
  <pre><code>             books.save()  
                              }).then(() =&gt; {
                      return books
                  })
              }
  </code></pre>
  
  <p>but then return books here is returning the promise and not the resolve. </p>
  
  <p><strong>Question:</strong> How can I return resolve after my MongoDB operation is over? (or in sync with MongoDB)</p>