As we have already covered usage examples for building-block and embedded documents in earlier chapters, let's now focus on how to use and create a document that relates to other documents using a common reference. As an example, let's look at the process of creating a Loan document. As you recall from the Loan collection data structure section in this chapter, the Loan document includes two references to the users collection: one for the borrower and another for the lender.
The users collection includes a unique field named userKey. When we create a loan document, all we need to do is to add the value of the userKey property for the lender, and the userKey value for the borrower.
The final loan document might appear as follows:
{
"_id" : ObjectId("5da950636f165e472c37a98d"),
"loanKey" : "LAMOHOLM1595_CHRIMARQ4459_20200303",
"borrowerKey" : "LAMOHOLM1595"...