title: Realm : delete specific object
body: <p>I'm developing app using react native where i need to delete specific objects which give me in filtered method but it gave me error called </p>
  
  <p>"Can only delete objects within a transaction."</p>
  
  <p>Here is my Code</p>
  
  <pre><code>allObj1 = {
                  id : 1,
                  speed : "1",
                  accuracy: "100",
                  bearing: "1",
                  longitude: "192",
                  altitude: "1111",
                  latitude: "1111",
                  time: "11111",
                  locationProvider: "2222",
              };
  
          allObj2 = {
                  id : 2,
                  speed : "1",
                  accuracy: "100",
                  bearing: "1",
                  longitude: "192",
                  altitude: "1111",
                  latitude: "1111",
                  time: "22222",
                  locationProvider: "2222",
              };
  
          allObj3 = {
                  id : 3,
                  speed : "1",
                  accuracy: "100",
                  bearing: "1",
                  longitude: "192",
                  altitude: "1111",
                  latitude: "1111",
                  time: "333333",
                  locationProvider: "2222",
              };
  
          realm.write(() =&gt; {
              realm.create('Location',allObj1 );          
              //realm.delete(firstObj);
              realm.create('Location',allObj2 );
              realm.create('Location',allObj3 );
          });         
  
          let locationO = realm.objects('Location');
          //let tanlocation = locationO.filtered('id &gt;1 AND id &lt;3 ');
          // Observe Collection Notifications         
  
          realm.objects('Location').filtered('id &gt;=1 AND id &lt;=3').addListener((tanlocation, changes) =&gt; {
  
              try{
                  tanlocation.forEach((realmObj,index) =&gt; {                           
                      realm.delete(realmObj);             
                  });
              }
              catch(err){
                  console.log(err);
              }
          });
  
  
          // Unregister all listeners
          realm.removeAllListeners();
  
          //realm.delete(tanlocation);
          //console.log( tanlocation );
  
          console.log(locationO);
  </code></pre>
  
  <p>It throw me error called "Can only delete objects within a transaction."</p>
  
  <p>anyone has faced this kind of issue? anybody knows how to fixed this or alternative method to achieved mentioned functionality</p>