pappus
pappus

Reputation: 761

Query json data on MongoDB

I have a rather complex structure on my json and I cannot find how to query it to get the rows I am interested in. Here is a sample of my data:

{
    "_id" : ObjectId("5282bf9ce4b05216ca1b68f8"),
    "authorID" : ObjectId("5282a8c3e4b0d7f4f4d07b9a"),
    "blogID" : "7180831558698033600",
    "blogs" : {
        "$" : {
            "posts" : [
                [
                    {
                        "author" : {
                            "displayName" : "mms",
                            ...
                            ...
                            ...
}}}

So, I am interested in finding all json entries that have the author displayName equal to "mms".

My collection name is bz so, a find all query would be: db.dz.find()

What criteria do I have to put inside the find() to only get json document with author displayName equal to mms?

Any ideas?

Thank you in advance!

Upvotes: 0

Views: 2020

Answers (1)

Wizard
Wizard

Reputation: 4431

Suppose you have replaced field name "$" with "dollarSign".

Then db.dz.find({"blogs.dollarSign.posts.author.displayName": "mms"}) will fetch whole documents according to your requirements.

Upvotes: 1

Related Questions