Wednesday, 7 June 2017

MongoDB Manual and DBRef referencing using node js

I have two case ,first case: where in my key has reference to the same collection ,is this correct way to reference ?,if yes ! how to de-ref/link in node js ?,if not how to reference fom the same collection

{
"_id" : ObjectId("53402597d852426020000002"),
"address" : {
    "$ref" : "home_adress"
},
"contact" : "987654321",
"dob" : "01-01-1991",
"name" : "Tom Benzamin",
"Post_address" : {
    "$ref" : "home_adress"
},   
"home_adress":"Street 1, NY"} 

case two: reference to a different collection(DBRefs),How to detect the reference and send the second query to fetch the referenced value ?

{
"_id" : ObjectId("53402597d852426020000002"),
"address" : {
    "$ref" : "address_home",
    "$id" : ObjectId("534009e4d852427820000002"),
    "$db" : "ref"
},
"contact" : "987654321",
"dob" : "01-01-1991",
"name" : "Tom Benzamin"}


{
"_id" : ObjectId("534009e4d852427820000002"),
"building" : "22 A, Indiana Apt",
"pincode" : 123456,
"city" : "Los Angeles",
"state" : "California"}



via Prem Sanil

No comments:

Post a Comment