stijnsanders / TMongoWire

Delphi MongoDB driver
MIT License
102 stars 37 forks source link

create record #30

Closed DDAGitHub closed 8 years ago

DDAGitHub commented 8 years ago

Hello. I can't understand how to create array of Objects in the created object. This code does not work — create simple array. d:=BSON([ '_id', 111, 'data',VarArrayOf(['[','f1',11,']','[','f2',22,']']), ]);

With best regards, Dmitry.

stijnsanders commented 8 years ago

use this:

d:=BSON([
'_id', 111,
'data',VarArrayOf([BSON(['f1',11]),BSON(['f2',22])])
]);    
DDAGitHub commented 8 years ago

Thank you very much!

DDAGitHub commented 8 years ago

Another question. Sorry, I'am novice in the Mongo+BSON. I have an object: { "_id" : "001", "data" : [ {"f1": "1"}, {"f2": "2" } ] } dSelector:=BSON(['_id', "001"]); d:=FMongoWire.Get(mwCollection,dSelector); How now I can get access to the data array? And how I can update such objects?

With best regards, Dmitry

stijnsanders commented 8 years ago

d['data'] will result in a variant array, you either use d['data'][0] if you know/assume the length, or use VarArrayHighBound and VarArrayLowBound to iterate. You can make modifications to the local object d and use it with FMongoWire.Update