#1 2024-02-22 13:12:14

rove
Member
Registered: 2024-02-22
Posts: 2

more than one results in AggregateDoc() - MongoDB

Hi!

I have some problems when using mORMot with function TMongoCollection.AggregateDoc.
When using $limit:1 in operators, one result is returned as variant. But how to obtain results in case
when using $limit:5?
For example:
var
  doc: variant;
begin
  doc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:1}', []); ===> single record in doc is returned, OK!
but
  doc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:5}', []); ===> multiple records as dvArray of TDocVariant should be returned(5 values)?

In multiple case, I did not able to read records from doc variable.

I am using Lazarus3.0

Offline

#2 2024-02-22 16:56:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: more than one results in AggregateDoc() - MongoDB

What is within doc? e.g. using string(doc) ?
Did you try to use _SafeArray(doc)^ to access the content?

I have added TMongoCollection.AggregateDocDict/AggregateDocList methods
since using IDocList may be easier for your usecase:
https://github.com/synopse/mORMot2/commit/d823a54f

Offline

#3 2024-03-01 08:43:12

rove
Member
Registered: 2024-02-22
Posts: 2

Re: more than one results in AggregateDoc() - MongoDB

Thank for you answer!

I migrated from mormot1 to mormot2 and the following code

doc: variant;
doc:=Coll.AggregateDoc('{ $sort : { _id: -1 } }, { $limit : 1 }',
        []);

does not return the result in mormot2, doc is empty.
But in mormot1, the function return one record.

What is the difference between mormot1 and mormot2?

Offline

#4 2024-03-01 13:46:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: more than one results in AggregateDoc() - MongoDB

There should not be any difference, I guess.

Offline

Board footer

Powered by FluxBB