compare two collections in mongodb using java or an simple query

1,101 views
Skip to first unread message

Parag Vaidya

unread,
May 6, 2014, 10:31:19 AM5/6/14
to mongod...@googlegroups.com

I am having following document (Json) of an gallery,

    {
        "_id": "53698b6092x3875407fefe7c",
        "status": "active",
        "colors": [
            "red",
            "green"
        ],
        "paintings": [
            {
                "name": "MonaLisa",
                "by": "LeonardodaVinci"
            },
            {
                "name": "JungleArc",
                "by": "RayBurggraf"
            }
        ]
    }

Now I am also having one collection of colors say
COLORS-COLLECTION: ["black","yellow","red","green","blue","pink"]
I want to fetch paintings by it's name matching to provided text say "MonaLisa" (as search query) also I want to compare two colors with COLORS-COLLECTION, if colors has any of the matching color in COLORS-COLLECTION then it should return the painting.
I want something like below:

 

    {
        "paintings": [
            {
                "name": "MonaLisa",
                "by": "LeonardodaVinci"
            }
        ]
    }

Please help me!!. Thanks in advance.

Keith Branton

unread,
May 6, 2014, 10:46:50 AM5/6/14
to mongod...@googlegroups.com
wouldn't the colors need to be nested in the paintings subdocuments for your example to work - i.e. a colors array for each painting?

the functionality you are looking for sounds like the first example shown on this page: http://docs.mongodb.org/manual/reference/operator/query/all/


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/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 post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/c6436127-97f7-422c-a288-6e84cf897a4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Parag Vaidya

unread,
May 7, 2014, 5:17:07 AM5/7/14
to mongod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages