Reputation: 1456
Hello i have the following collections of produucts that contains DBRef object my issue is how to queryall product collections for the category C1 or C2 this is my shema :
{ "_id" : ObjectId("5c27a71"), "name" : "HP", "price" : 837.10, "category" : DBRef("category", "C1"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a36"), "name" : "DELL", "price" : 489.10, "category" : DBRef("category", "C1"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a20"), "name" : "ASUS", "price" : 334.01, "category" : DBRef("category", "C1"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a78"), "name" : "LENEVO", "price" : 76.21, "category" : DBRef("category", "C1"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a74"), "name" : "THINKPAD", "price" : 500.84, "category" : DBRef("category", "C1"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a23"), "name" : "AX3D", "price" : 186.28, "category" : DBRef("category", "C2"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a12"), "name" : "BAF5", "price" : 614.58, "category" : DBRef("category", "C2"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a78"), "name" : "COMPAX MAX", "price" : 791.92, "category" : DBRef("category", "C2"), "_class" : "com.entities.Product" }
{ "_id" : ObjectId("5c27a54"), "name" : "GERO 55K", "price" : 576.28, "category" : DBRef("category", "C2"), "_class" : "com.entities.Product" }
this is the shema of category document :
{ "_id" : "C1", "name" : "Ordinateurs", "products" : [ ], "_class" : "com.entities.Category" }
{ "_id" : "C2", "name" : "Imprimantes", "products" : [ ], "_class" : "com.entities.Category" }
do you have any idea on how to query all product for specefic category.
thanks in advance
Upvotes: 0
Views: 49
Reputation: 504
You should try this As mentioned in the mongodb Docs
db.collectionsName.find(
{ category: { $in: [ DBRef("category", "C1"), DBRef("category", "C2") ] } }
)
Upvotes: 1