Realm - Select multiple rows

254 Views Asked by At

I have a mongodb-realm object(collection) named 'Products':

THE SCHEMA:

const Products = {

  name: "Products",

  properties: {

      _id: "objectId",
      name : "string",
    }
}

THE DATA

_id:'60f73ca7c1a70278596cc7d0',
products:[
      {_id:1, name: 'product1'},
      {_id:2, name: 'product2'},
      {_id:3, name: 'product3'},
      {_id:4, name: 'product'}
]

Now, I want to select some(say two) of these using realm. In this case I want to filter product1 and product2. I'm trying to put the ids in an array and try to filter them but it doesn't work. Below is my code

const obj = realm.objects('Products').filtered("_id == $0", [ObjectId('1'), ObjectId('2')])

Now My question is: How can I filter multiple rows in realm? And as my example above, how can I filter product1 and product2?

0

There are 0 best solutions below