List number of related products as the answer

125 views
Skip to first unread message

jain shah

unread,
Mar 4, 2020, 8:07:47 AM3/4/20
to mongodb-user

My database is a collection of items on ebay. I want to list the number of related items that come up with the item "Stop watch". I only want the number of related items as the answer. So far i have the code as shown below which gives me an error. Could someone please help me.

db.getCollection('products').aggregate([ {$match: {product: {"Stop Watch"}}}, { $group:{ _id: {related: "$related", product: "$title"}}},{$count:"relatedAndProduct"} ])

This code gives me an error.

Stennie

unread,
Mar 4, 2020, 8:12:53 AM3/4/20
to mongodb-user
This question was also posted on the MongoDB Community site: List number of related products as the answer.

It would be best to continue any discussion on the MongoDB Community site, which is the replacement for this Google Group.

Thanks,
Stennie

Stephen Isienyi

unread,
Mar 4, 2020, 2:58:15 PM3/4/20
to mongod...@googlegroups.com
Hi Jain, remove the curly braces around “Stop Watch” and see how it goes.

Also provide the error message received if you still need some help with this afterwards.


On Mar 4, 2020, at 05:07, jain shah <uria...@gmail.com> wrote:



My database is a collection of items on ebay. I want to list the number of related items that come up with the item "Stop watch". I only want the number of related items as the answer. So far i have the code as shown below which gives me an error. Could someone please help me.

db.getCollection('products').aggregate([ {$match: {product: {"Stop Watch"}}}, { $group:{ _id: {related: "$related", product: "$title"}}},{$count:"relatedAndProduct"} ])

This code gives me an error.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1dc789de-ed3c-44e4-bd99-8d7edbd72e42%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages