# Get entries with range?

**URL:** <https://discourse.getcockpit.com/t/get-entries-with-range/42>\
**Category:** Support\
**Created:** [May 3, 2018, 11:49am UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42 "2018-05-03T11:49:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastiankolind](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/sebastiankolind/32/9_2.png) [@sebastiankolind](https://discourse.getcockpit.com/u/sebastiankolind)\
**Post date:** [May 3, 2018, 11:49am UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/1 "2018-05-03T11:49:02Z")

</div>

Hello.

I am trying to get a range of entries based on an ID field I created in my collection. Not the basic Cockpit \_id field, but a custom one. Is it possible in some way?

I need it to get orders with ID from x to x.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [May 3, 2018, 12:42pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/2 "2018-05-03T12:42:55Z")

</div>

maybe something like this:

```php

{
  $and: [
    {myfield: {$gt: x}},
    {myfield: {$lt: y}}
  ]
}

```

---

<div class="post-metadata">

**Author:** ![sebastiankolind](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/sebastiankolind/32/9_2.png) [@sebastiankolind](https://discourse.getcockpit.com/u/sebastiankolind)\
**Post date:** [May 3, 2018, 1:04pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/3 "2018-05-03T13:04:06Z")

</div>

I am not sure how this would work in practice? Is this going into the `data: {}` property of for example an axios or fetch request?

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [May 3, 2018, 1:19pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/4 "2018-05-03T13:19:57Z")

</div>

```auto
fetch('/api/collections/get/posts?token=xxtokenxx', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        filter: {
             $and: [
               {myfield: {$gt: x}},
               {myfield: {$lt: y}}
             ]
        }
    })
})
.then(res=>res.json())
.then(res => console.log(res));

```

---

<div class="post-metadata">

**Author:** ![sebastiankolind](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/sebastiankolind/32/9_2.png) [@sebastiankolind](https://discourse.getcockpit.com/u/sebastiankolind)\
**Post date:** [May 3, 2018, 1:25pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/5 "2018-05-03T13:25:42Z")

</div>

Thank you.

I had no idea that `$and` existed. Do you have a list of properties to filter on some where? 🙂

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [May 3, 2018, 1:41pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/6 "2018-05-03T13:41:06Z")

</div>

If you’re using MongoDB as datasource than I would suggest reading the official docs: [https://docs.mongodb.com/v3.2/tutorial/query-documents/](https://docs.mongodb.com/v3.2/tutorial/query-documents/)

the sqlite based solution doesn’t support the full query feature-set (see [https://github.com/agentejo/cockpit/blob/next/lib/MongoLite/Database.php#L225](https://github.com/agentejo/cockpit/blob/next/lib/MongoLite/Database.php#L225))

---

<div class="post-metadata">

**Author:** ![sebastiankolind](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/sebastiankolind/32/9_2.png) [@sebastiankolind](https://discourse.getcockpit.com/u/sebastiankolind)\
**Post date:** [May 3, 2018, 1:53pm UTC](https://discourse.getcockpit.com/t/get-entries-with-range/42/7 "2018-05-03T13:53:42Z")

</div>

Ahh, I see. Thank you so much.  
I didn’t know that the collection calls was passed 1:1 to mongoDB queries.
