You are not logged in.
Hi!
I got some problem when using mORMot for TMongoCollection.AggregateDoc
var
LDoc: variant;
LDoc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:1}', []); ===> single value is returned, OK!
but
LDoc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:5}', []); ===> multiple values are returned(5 values)
In this case, how to access the second value like: Lvar[1].value;
According to the manual:
if LDoc._kind = ord(dvArray) then ===> error occured here that "Invalid variant type 0 invoke"
begin
showmessage(LDoc._(1));
end;
Help me please!
Offline
I have executed as below:
var
AQry: string;
LDoc: variant;
AQry := '{ aggregate: "COLLECTNAME", pipeline: [{$sort:{_id:-1}},{$limit:5}], allowDiskUse: true}';
FDB.RunCommand(BSONVariant(AQry), LDoc);
with debugging LDoc, LDoc has a data, not null;
but
showmessage(Utf8ToString(VariantToUtf8(LDoc.Value))); ===> "null" displayed
Last edited by bigheart (2014-10-02 09:15:10)
Offline
LDoc contents are datetime and "a":"1" format data.
When debugging with "class procedure TDocVariant.GetSingleOrDefault" function in SynCommons.pas is excuted,
recursive call itself one time.
Trace into that function again,
TDocVariant(DocVariantArray).count is 5,
also TDocVariantData(DocVariantArray).Values[0] ~ TDocVariantData(DocVariantArray).Values[4] has exact data what i want.
But condition as "TDocVariant(DocVariantArray).count <> 1" in GetSingleOrDefault(...) function,
result := default;
is excuted;
And next "result" is not assigned.
How can i have multiple data from AggregateDoc(...).
Offline
Yes, I got error when the data is more than 2. How to solve it when I got more than one in AggregateDoc()?
Offline
is any TDocVariantVariant in mormot? because i have already typed it and Undefined the class
Offline
is any TDocVariantVariant in mormot? because i have already typed it and Undefined the class
It was a typo error, he meant TDocVariantData
Offline