Monday, 9 August 2021

ArangoDB: limit(): limit number of documents to be returned

‘limit()’ method limit the number of documents returned.

 

Example

127.0.0.1:8529@abc_org> db.user.all().toArray()
[ 
  { 
    "_key" : "15750", 
    "_id" : "user/15750", 
    "_rev" : "_cReWUTe---", 
    "id" : 1, 
    "name" : "Sailu" 
  }, 
  { 
    "_key" : "15758", 
    "_id" : "user/15758", 
    "_rev" : "_cReWbIK---", 
    "id" : 2, 
    "name" : "Ram" 
  }, 
  { 
    "_key" : "15766", 
    "_id" : "user/15766", 
    "_rev" : "_cReWhcu---", 
    "id" : 3, 
    "name" : "Gopi" 
  }, 
  { 
    "_key" : "15774", 
    "_id" : "user/15774", 
    "_rev" : "_cReWo3e---", 
    "id" : 4, 
    "name" : "Joel" 
  } 
]

 

As you above snippet user Collection has 4 documents in it. Let’s limit the results to 2 using limit method.

127.0.0.1:8529@abc_org> db.user.all().limit(2).toArray()
[ 
  { 
    "_key" : "15750", 
    "_id" : "user/15750", 
    "_rev" : "_cReWUTe---", 
    "id" : 1, 
    "name" : "Sailu" 
  }, 
  { 
    "_key" : "15758", 
    "_id" : "user/15758", 
    "_rev" : "_cReWbIK---", 
    "id" : 2, 
    "name" : "Ram" 
  } 
]

 

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment