title: why my condition expression for attribute not exist fails in dynamodb
body: <p>My DynamoDB table has a primary key as <code>id</code>. <strong>The same id will be used to query a record.</strong></p>
  <p>Now I want to insert a record with <code>id</code> and <code>originalURL</code> as attributes, I want to insert this record if and only if the <code>id</code> and <code>originalURL</code> doesn't exist in the table.</p>
  <p>Update :- <code>ConditionExpression: &quot;attribute_not_exists(id) AND attribute_not_exists(originalURL)&quot;</code> will only works in the context of primary key,<a href="https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html" rel="nofollow noreferrer">according to docs</a><strong>(You can perform a conditional put operation (add a new item if one with the specified primary key doesn't exist)</strong> ,so <code>attribute_not_exists(originalURL)</code> is there or not it doesn't make a difference.<strong>so i need either a solution where both the conditions work or originalURL also act as a key</strong></p>
  <pre><code>router.post('/', async function (req, res, next) {
  
    urlId = await nanoid(8);
  
  
    //const hashids = new Hashids('this is my salt')
    //urlId=hashids.encode(1)
    console.log('jatin', urlId);
    // urlId=uuidv4();
  
    const { longURL } = req.body
  
    const params = {
      TableName: 'url',
      Item: {
        &quot;id&quot;: urlId,
        &quot;originalURL&quot;: longURL
      },
      UpdateExpression: &quot;set originalURL = :y&quot;,
      ConditionExpression: &quot;attribute_not_exists(id) AND attribute_not_exists(originalURL)&quot;
    }
    dynamoDb.put(params, (error, data) =&gt; {
      if (error) {
        console.log(error);
        res.status(400).json({ error: error });
      } else if (Object.keys(data).length === 0 &amp;&amp; data.constructor === Object) {
        res.status(200).json(
          {
            urlId,
            longURL,
            status: 'success'
          })
      }
  
      else {
        res.status(400).json({ error: 'Please try again' });
      }
    })
  });
  </code></pre>
  <p>as of now even if i try to send a request with sam original URL which is already present it successfully adds the record which I don't want.</p>