doclite
doclite copied to clipboard
not creating new document
Hi Doclite,
thank you for the awesome library,
is there any built-in function for example to get the count of documents in a collection, and such functions? (like the last id)
if not, is there any high-performance solution to do it, rather than querying all the documents and calculating the array count
regards
@dwgebler @Awilum @iGusev
any idea here ?
also, what if we want to do a search with an array, like sleek DB for example
$collection->where([[['__id', '!=', ""], "OR", ['role', '=', "admin"]], "AND", ['age', '<', "50"]])->fetch()
how will be the scenario with doclite ?
regards
@REDAL in answer to your first question, yes the query builder has a count() method, e.g.
$numUsers = $users->where('active', '=', true)->count();
In regards to your second question, you can't use an array as search criteria but you chain conditions on the query builder as much as you like using and()
and or()
functions, e.g.:
$users->where('registered', '=', true)->and('active', '=', false)->fetch();
Please see the advanced queries section of the documentation
https://github.com/dwgebler/doclite#advanced-queries
Hii Dwgebler, Thank you for your reply,
Yes, I used, those functions, but in the scenario above, where 2 criteria are related, with OR ?
Regards
From: dwgebler @.> Sent: Friday, September 2, 2022 12:43:39 AM To: dwgebler/doclite @.> Cc: redaloui @.>; Mention @.> Subject: Re: [dwgebler/doclite] not creating new document (Issue #21)
@REDALhttps://github.com/REDAL in answer to your first question, yes the query builder has a count() method, e.g.
$numUsers = $users->where('active', '=', true)->count();
In regards to your second question, you can't use an array as search criteria but you chain conditions on the query builder as much as you like using and() and or() functions, e.g.:
$users->where('registered', '=', true)->and('active', '=', false)->fetch();
Please see the advanced queries section of the documentation
https://github.com/dwgebler/doclite#advanced-queries
— Reply to this email directly, view it on GitHubhttps://github.com/dwgebler/doclite/issues/21#issuecomment-1234915034, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABZR4KFXDEREJTXWJRN6IALV4E5SXANCNFSM6AAAAAAQBZRRZM. You are receiving this because you were mentioned.Message ID: @.***>
@REDAL there is an example in the advanced queries section of the documentation - if I understand correctly what you're trying to do, you want the union()
and intersect()
functions which allow you to group clauses. An example of an efficient count with grouped clauses:
/ / Get the total number of users where (active=true AND email != "") OR (active=false AND email == "")
$numUsers = $users->where('active', '=', true)->and('email, 'NOT EMPTY')->union()->where('active', '=', false)->and('email', 'EMPTY)->count();
union()
groups the clauses on either side by OR,intersect()
groups the clauses on either side by AND.
The combination of all query functions, where()
, and()
, or()
, union()
and intersect()
can be chained as much as you like to create whatever query you need.
Thank you very much will try it now 😎🙏
Kindest regards
From: dwgebler @.> Sent: Friday, September 2, 2022 12:42:33 PM To: dwgebler/doclite @.> Cc: redaloui @.>; Mention @.> Subject: Re: [dwgebler/doclite] not creating new document (Issue #21)
@REDALhttps://github.com/REDAL there is an example in the advanced queries section of the documentation - if I understand correctly what you're trying to do, you want the union() and intersect() functions which allow you to group clauses. An example of an efficient count with grouped clauses:
/ / Get the total number of users where (active=true AND email != "") OR (active=false AND email == "") $numUsers = $users->where('active', '=', true)->and('email, 'NOT EMPTY')->union()->where('active', '=', false)->and('email', 'EMPTY)->count();
union() groups the clauses on either side by OR,intersect() groups the clauses on either side by AND.
The combination of all query functions, where(), and(), or(), union() and intersect() can be chained as much as you like to create whatever query you need.
— Reply to this email directly, view it on GitHubhttps://github.com/dwgebler/doclite/issues/21#issuecomment-1235396518, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABZR4KBEDXZOXW53QVFP5YLV4HR2TANCNFSM6AAAAAAQBZRRZM. You are receiving this because you were mentioned.Message ID: @.***>
@dwgebler it worked like a charm :)
what about getting the last ID? , is there any built-in function , or how you do it
regards
There isn't any concept of a "last ID" in DocLite since the ID can be any unique string value. If you want to know the ID of a newly saved document, you can just call $document->getId()
after saving it. Otherwise if you want to know the ID of the last (meaning most recent) document in a collection, you need to save that information yourself by e.g. adding a field to that document to record the DateTime
it was created. Additionally, a DateTime
can be extracted from auto generated IDs by calling the getTime()
method on a document, see https://github.com/dwgebler/doclite#document-unique-id but there isn't a way to query by that, since a document ID doesn't have to be a UUID as long as it is something unique.