Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Load MongoDB cursor into TListView?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 7, 2016 11:53 PM Last Post By: SQL Daddy
Bob Johnson

Posts: 28
Registered: 9/11/15
Load MongoDB cursor into TListView?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 9, 2016 6:36 AM
How can I load the data that gets returned in the MongoDB cursor into a TListView?

Thanks!
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: Load MongoDB cursor into TListView?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 11, 2016 1:37 AM   in response to: Bob Johnson in response to: Bob Johnson
Bob Johnson wrote:

procedure TForm162.Button1Click(Sender: TObject);
var
  oCrs: IMongoCursor;
  oIter: TJSONIterator;
  oItem: TListItem;
begin
  oCrs := FCon['test']['restaurants'].Find()
    .Match()
      .Add('cuisine', 'Italian')
      .Add('address.zipcode', '10075')
    .&End;
 
  ListView1.Items.Clear;
  ListView1.Columns.Clear;
  ListView1.Columns.Add.Caption := 'Name';
  ListView1.Columns.Add.Caption := 'street';
  ListView1.Columns.Add.Caption := 'building';
  ListView1.Columns.Add.Caption := 'borough';
  ListView1.ViewStyle := vsReport;
 
  while oCrs.Next do begin
    oItem := ListView1.Items.Add;
    oIter := oCrs.Doc.Iterator;
    try
      if oIter.Find('name') then
        oItem.Caption := oIter.AsString;
      if oIter.Find('address.street') then
        oItem.SubItems.Add(oIter.AsString)
      else
        oItem.SubItems.Add('');
      if oIter.Find('address.building') then
        oItem.SubItems.Add(oIter.AsString)
      else
        oItem.SubItems.Add('');
      if oIter.Find('borough') then
        oItem.SubItems.Add(oIter.AsString)
      else
        oItem.SubItems.Add('');
    finally
      oIter.Free;
    end;
  end;
end;


But note, this is not optimal, because TJSONIterator.Find restarts iteration.
For large volume of data and/or big documents you should iterate through
document items, check Key value and decide what you will do with this
item.

--
With best regards,
Dmitry
SQL Daddy

Posts: 6
Registered: 4/8/16
Re: Load MongoDB cursor into TListView?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 7, 2016 11:53 PM   in response to: Bob Johnson in response to: Bob Johnson
Hello,

I have got the solution about that How to load Mongodb cursor into Tlistview. Here I am sharing the code,

using (MongoDB.Driver.ICursor cur = ex_col.Find(new MongoDB.Driver.Document() { { "id", 3 } }))

If you need more help, You can see complete article here

http://www.codeguru.com/csharp/article.php/c17515/MongoDB-and-C-Programming-the-NonSQL-Way.htm

I have also got more relevant article, Like how to do task like MONGODB UpSert ,Load Data into MONGODB ,MONGODB Delete ,MONGODB Update

See detail about task

https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02