Sintaxis para dbref es
{ $ref : <collname>, $id : <idvalue>[, $db : <dbname>] }
Pero ha agregado un campo de cantidad no compatible dentro de dbref. Ese es el problema. lleva eso afuera
db.basket.save ({"_id" : "1", "items" : [
{"quantity" : 5 , item : {"$ref" : "fruit", "$id" : "1"}},
{"quantity" : 10, item : {"$ref" : "fruit", "$id" : "3"}}
]})
qué tipo de miradas (miedo)
{
"_id" : "1",
"items" : [
{
"quantity" : 5,
"item" : {
"$ref" : "fruit",
"$id" : "1"
}
},
{
"quantity" : 10,
"item" : {
"$ref" : "fruit",
"$id" : "3"
}
}
]
}
Pero mi consejo es, deshazte del dbref por completo y solo usa la estructura simple como esta
db.basket.save ({"_id" : "1",items:[
{item_id:"1",quantity:50},
{item_id:"3",quantity:10}
]})
esto es mucho más limpio, que se verá como
{
"_id" : "1",
"items" : [
{
"item_id" : "1",
"quantity" : 50
},
{
"item_id" : "3",
"quantity" : 10
}
]
}