Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: TMongoCollection Update howto push array of objects ($push $each)



Permlink Replies: 2 - Last Post: Aug 22, 2016 11:44 PM Last Post By: Gaetano Mantovani
Gaetano Mantovani

Posts: 19
Registered: 8/30/14
TMongoCollection Update howto push array of objects ($push $each)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 12:43 AM
Hi all,
I'm trying to push an array of objects into an existing document.

So here the Firedac wiki
http://docwiki.embarcadero.com/Libraries/Seattle/en/FireDAC.Phys.MongoDBWrapper.TMongoCollection.Update

here the example code of MongoDb Manual
https://docs.mongodb.com/manual/reference/operator/update/push/
below the kind of command that I need:

db.students.update(
{ _id: 5 },
{
$push: {
quizzes: {
$each: [ { wk: 5, score: 8 }, { wk: 6, score: 7 }, { wk: 7, score: 6 } ],
$sort: { score: -1 },
$slice: 3
}
}
}
)

so how to convert the above code in c++builder?

oCol->Update()
->Match()
->Add("_id", TJsonOid(MyId))
->End()
->Modify()
->Push()
->Field("quizzes",??)
->End()
->End()
->Exec();

In the meantime I solved using a TMongoCommand.

Thank you in advance
Dmitry Arefiev

Posts: 1,406
Registered: 12/7/03
Re: TMongoCollection Update howto push array of objects ($push $each)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 9:28 PM   in response to: Gaetano Mantovani in response to: Gaetano Mantovani
See demo: CPP\Database\FireDAC\Samples\DBMS Specific\MongoDB\General,
fMain.cpp, TfrmMain::btnUpdPushClick

--
With best regards,
Dmitry
Gaetano Mantovani

Posts: 19
Registered: 8/30/14
Re: TMongoCollection Update howto push array of objects ($push $each)
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 11:44 PM   in response to: Dmitry Arefiev in response to: Dmitry Arefiev
Oh thank you so much don't know how, but I read the code of the examples and I missed this specific part.
Bye

Dmitry Arefiev wrote:
See demo: CPP\Database\FireDAC\Samples\DBMS Specific\MongoDB\General,
fMain.cpp, TfrmMain::btnUpdPushClick

--
With best regards,
Dmitry
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02