title: Firebase rules not allowing user to write data in android
body: <p>This is database structure.</p>
  
  <p><a href="https://i.stack.imgur.com/qqPEg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qqPEg.png" alt="enter image description here"></a></p>
  
  <p>This is database rules:</p>
  
  <pre><code>{
    "rules": {
      ".read": true,
      "shops-product-list": {
          "$uid": {
  
          // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
          ".write": "auth !== null &amp;&amp; auth.uid === $uid",
          }
      }
    }
  }
  </code></pre>
  
  <p>key for shops-products-list is logged-in user's uid (ignore first key i.e. -1)</p>
  
  <p>Logged user trying to write new data with this logic.</p>
  
  <pre><code>private void addShopVariant(String pid, String vid, String mrp, String sellPrice) {
      // Create new post at /user-posts/$userid/$postid and at
      // /posts/$postid simultaneously
  
      final String uid = getUid();
      String key = pid + "_" + vid;
      //String key = databaseReference.child("shops-product-list").child(uid).push().getKey();
  
      ShopProductVariant shopProductVariant = new ShopProductVariant(pid, vid, mrp, sellPrice);
      Map&lt;String, Object&gt; shopProductVariantValues = shopProductVariant.toMap();
      Map&lt;String, Object&gt; childUpdates = new HashMap&lt;&gt;();
      childUpdates.put("/shops-product-list/" + uid + "/"+ key, shopProductVariantValues);
      //childUpdates.put("/user-posts/" + userId + "/" + key, postValues);
  
      databaseReference.updateChildren(childUpdates);
  }
  </code></pre>
  
  <p>Function works fine if i set rules.</p>
  
  <pre><code>{
    "rules": {
      ".read": true,
      ".write": true
    }
  }
  </code></pre>
  
  <p>But i want only logged-in  user should be able to write, that too only their own data.</p>
  
  <p>what is wrong is above firebase rules?</p>