Question

In MongoDB there is a nice tutorial on Manual Reference:

Example:

original_id = ObjectId()

db.places.insert({
    "_id": original_id,
    "name": "Broadway Center",
    "url": "bc.example.net"
})

db.people.insert({
    "name": "Erin",
    "places_id": original_id,
    "url":  "bc.example.net/Erin"
})

Note, that this two documents are created at same time.

Question. I need to reference a Customer with an Order, therefore the Customer has been created long time before the Order, how can I add this reference of customer and insert in Order?

Was it helpful?

Solution

Wouldn't you need to do a findOne() on your customer first and add it's id property to your new document?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top