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.
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.
maybe something like this:
{
$and: [
{myfield: {$gt: x}},
{myfield: {$lt: y}}
]
}
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?
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));
Thank you.
I had no idea that $and
existed. Do you have a list of properties to filter on some where?
If you’re using MongoDB as datasource than I would suggest reading the official docs: 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)
Ahh, I see. Thank you so much.
I didn’t know that the collection calls was passed 1:1 to mongoDB queries.