Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56139

JSON based query to identify if there are any other field present apart from provided one

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Duplicate
    • Icon: Critical - P2 Critical - P2
    • None
    • None
    • None
    • None

    Description

      Hi Team,

      We are working on the following case where we need the confirmation of the behaviour.
       
      let's consider the following example,where "test" json object will have keys.
      {
      "_id": ObjectID('123'),
      "test":

      { "a":1, "b":1 }

      },
      {
      "_id": ObjectID('456'),
      "test":

      { "a":1 }

      We wanted to filter all the documents where "test" json does have any key other than `"a": 1`.
       
      So, we went to search for the solution and tried the following, which provided the expected result. We also put the index on the "test" field to avoid any performance issues and it worked as well.
      db.col.find({"test": {"$gt":

      {"a": 1}

      }})
       
      But did not find any such query or case on MongoDB official site, so just looking out for the support that this is a proper solution and there is no downside to it.

      Thanks,

      Attachments

        Activity

          People

            Unassigned Unassigned
            hitesh.baldaniya@contentstack.com Hitesh Baldaniya
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: