#1 2021-04-22 09:42:13

Zebedee
Member
Registered: 2019-01-11
Posts: 3

MongoDB Distinct Query

Hello there.
I would like to write the following query exactly.

db.inventory.distinct( "sizes" )

But I couldn't find how to write this in Mormot.

https://docs.mongodb.com/manual/referen … thod-array

I tried the following methods and the like but failed.
Can you help me please.

var  DB: TMongoDatabase;
  vDocData: TDocVariantData;
begin
  DB :=  MongoCli.Open('core');
  DB.RunCommand('getCollection(''inventory'').distinct( "Sizes" )', retVal);
  DB.RunCommand('inventory.distinct( "Sizes" )', retVal);

  vDocData.InitJSON(VariantToUTF8(DB.Collection['inventory'].FindDoc('distinct( "Sizes" )', [])));
  // Server.Retrieve('inventory.distinct( "Sizes" )')
end;

Offline

#2 2021-04-22 16:14:13

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

Re: MongoDB Distinct Query

You need to use a pipeline.

Check how the MongoDB client implements the distinct() JavaScript function.
inventory.distinct() is a MongoDB client-only function: the MongoDB server only knows pipelines.

Offline

Board footer

Powered by FluxBB