Thursday 12 August 2021

ArangoDB: range, closedRange: Get all the documents where attribute is in given range

Signature

collection.range(attribute, left, right)

collection.closedRange(attribute, left, right)

 

‘range’ method returns all the documents from a collection such that the attribute is greater or equal than left and strictly less than right.

 

‘closedRange’ method returns all documents of a collection such that the attribute is greater or equal than left and less or equal than right.

 

Nested attributes are represented using . notation (like a.b.c)

 

All the documents from user collection

127.0.0.1:8529@abc_org> db.user.all().toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  }, 
  { 
    "_key" : "17095", 
    "_id" : "user/17095", 
    "_rev" : "_cRe1H-6---", 
    "id" : 4, 
    "firstName" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  } 
]

range method example

127.0.0.1:8529@abc_org> db.user.range("age", 32, 35).toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  } 
]


closedRange method example

127.0.0.1:8529@abc_org> db.user.closedRange("age", 32, 35).toArray()
[ 
  { 
    "_key" : "17089", 
    "_id" : "user/17089", 
    "_rev" : "_cRe1GKq---", 
    "id" : 1, 
    "firstName" : "Sailu", 
    "lastName" : "Ptr", 
    "age" : 32 
  }, 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17093", 
    "_id" : "user/17093", 
    "_rev" : "_cRe1GKy---", 
    "id" : 3, 
    "firstName" : "Krishna", 
    "lastName" : "Gurram", 
    "age" : 32 
  }, 
  { 
    "_key" : "17095", 
    "_id" : "user/17095", 
    "_rev" : "_cRe1H-6---", 
    "id" : 4, 
    "firstName" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  } 
]


Previous                                                    Next                                                    Home

No comments:

Post a Comment