Wildcard Search in mongoDB

Asked 2 years ago, Updated 2 years ago, 126 views

I would like to obtain a document with a key of "0001" (first and third)
in the following documents. However, the nested depth of the value of "0001" is not unique.

db.collection.find({"0001":wildcard})

I'm wondering if it's designated like this, but it doesn't work.
Please let me know.

{
    "0001": {"test1":"AAA"}
},
{
    "0002": {"test2": {"BBB": {"bbb": "ooo"}
},
{
    "0001": {"test3": {"CCC": "ccc"}}
}

mongodb

2022-09-30 21:38

1 Answers

db.collection.find({"0001":{$exists:true}})

You'll get the results you're looking forward to!


2022-09-30 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.