skip to Main Content

I want to search for all documents that have 255255 as their key value. the id on top is the id of the document.

"id" : "555114",
    "255255" : {
        "someField" : null,
    },
    "255256" : {
        "someField" : null,
    },

2

Answers


  1. You can use $exist to check if the key is present in document or not.

    db.yourCollection.find({"255255":{$exist:true}})
    
    Login or Signup to reply.
  2. You can use the exists operator.

    From the MongoDB docs:

    Syntax: { field: { $exists: <boolean> } }

    When <boolean> is true, $exists matches the documents that contain the field, including documents where the field value is null. If <boolean> is false, the query returns only the documents that do not contain the field

    db.yourcollection.find({ 255255: { $exists: true } });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search