0

How to retrieve two or more fields by using TUniQuery (from UniDAC Library) in Delphi accessing MongoDB?

Example: when using MongoSH, it's possible to do equivalent retrieve like this:

db.myCollection.find({}, {Id: 1, Number: 1})

Result is:

{
  _id: ObjectId("6463d53f8e2260611bed7216"),
  Id: 575682,
  Number: '99621800'
},
{
  _id: ObjectId("6463d53f8e2260611bed7217"),
  Id: 578559,
  Number: '364543222'
},
.
.
.

In Delphi, it works like this:

UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Text := '{"find":"myCollection", "filter":{Id: 530142}}';
UniQuery1.Open;

In the example above I can't include fields "Id" and "Number".

How to do the same retrieve by using TUniQuery (UniDAC) in Delphi with MongoDB?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
wBB
  • 821
  • 1
  • 18
  • 39
  • 1
    The `{Id: 1, Number: 1}` is projection configuration. Idk `unidac`, but I would try something like: `{"find":"myCollection", "filter":{Id: 530142}, {Id: 1, Number: 1}}` or `{"find":"myCollection", "filter":{Id: 530142}, "projection" : {Id: 1, Number: 1}}`, try playing with this – dododo May 16 '23 at 21:02

1 Answers1

0

It works like @dododo:

UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Text := '{"find":"myCollection", "filter":{"Id": 535662}, "projection": {Id: 1, Number: 1}}';
UniQuery1.Open;

Thanks @dododo!

wBB
  • 821
  • 1
  • 18
  • 39