Re: [Pharo-project] MongoTalk update
Hi, this seems to answer your question. http://articles.tulipemoutarde.be/embedded-document-with-voyage-in-mongodb Fernando On Sun, Nov 25, 2012 at 2:09 AM, Igor Stasenko <siguctua@gmail.com> wrote:
On 24 November 2012 14:06, Nicolas Petton <petton.nicolas@gmail.com> wrote:
Thanks Norbert!
It's cool to know that you like it :) Together with Esteban's work on Voyage, it allows us to do extremely cool stuff with Mongo and Pharo.
What I like with Voyage-Mongo + MongoQueries is that objects are persisted without any effort, it just works, and we can query Mongo collections like we would do with Smalltalk collections.
are you talking about serializing objects (or subgraphs) directly, and storing them in mongo db ?
Nico
Norbert Hartl <norbert@hartl.name> writes:
Hey Nico,
I looked into your new stuff and I like it. Especially the MongoQueries stuff is very simple and clean approach to do a small DSL. That boosts the usability of MongoTalk extremely. Bravo!
Norbert
Am 19.11.2012 um 15:37 schrieb Nicolas Petton <petton.nicolas@gmail.com :
Hi guys,
Lately I worked a bit on the Pharo Mongo driver for SmalltalkHub. I
made
several changes (in the new version 1.4):
The query API changed:
- MongoCollection>>query: now takes a 1 arg block, improving the API quite a bit.
Queries like:
aCollection query: (aCollection query query: { 'foo' -> 'bar'} asDictionary; yourself)
Is now written:
aCollection query: [ :query | query where: { 'foo' -> 'bar'} ]
Sending #asDictionary has also been made optional, the query builder will send #asMongoQuery to the query collection.
The MongoQueries package:
Version 1.4 comes with a new package MongoQueries, a small DSL allowing us to use traditional blocks instead of dictionaries to perform queries. This is optional and backward compatible.
Queries like:
aCollection select: { '$or' -> { 'name' -> 'foo'. 'age' -> { '$gt' -> 23 } asDictionary } asDictionary } asDictionary
can be expressed:
aCollection select: [ :each | (each name = 'foo') | (each age > 23) ]
The MongoQueries package should support the entire mongo query language (including nested queries), and comes with unit tests.
Nico
-- Nicolas Petton http://nicolas-petton.fr
-- Best regards, Igor Stasenko.
On 25/11/12 5:04 AM, Fernando Olivero wrote:
Hi, this seems to answer your question.
http://articles.tulipemoutarde.be/embedded-document-with-voyage-in-mongodb
The model in that article has a one-to-many relation between a Spaceship and Pilots. The Pilot isPersistent/isRoot, so has its own MongoDB collection. IIUC, if Pilot were not persistent/root, then the collection of pilots would be serialized along with the Spaceship object, and there would be no separate Pilot collection in MongeDB. So my question is, how does MongoTalk handle the editing of the pilot collection, when it's embedded into the Spaceship. For example, if a pilot is added, removed, or updated, does the entire embedded collection get re-saved, or does a suitable MongoDB update query get generated?
MontoTalk does not handle it. Voyage does :) but... an "embedded collection" sounds strange to me... I don't really think that is correct. There is no such thing like embedded collection in a mongodb sense (If I'm understanding right you question). Let's say you have for example this: ObjectA(ObjectB, CollectionOfObjectC) If ObjectA is marked as Root, you will save a document with ObjectB and a collection of ObjectC embedded into it (but is not an embedded collection, is just a document who has embedded objects, no matter if that object happens to be an array or any kind of smalltalk collection). but, for example, if ObjectC is marked as a Root too, Voyage will save ObjectA as a document with a list of references to ObjectC. Then your database will have two collections: ObjectAs and ObjectCs Other thing is that Voyage is just a mapper, not a complete DB implementation, so, if you remove ObjectA (for instance), and there are not more references to ObjectC, you need to remove it from database manually, nor mongo, nor mongotalk, not voyage will handle that kind of situations for you :) Esteban On Nov 26, 2012, at 5:53 PM, Yanni Chiu <yanni@rogers.com> wrote:
On 25/11/12 5:04 AM, Fernando Olivero wrote:
Hi, this seems to answer your question.
http://articles.tulipemoutarde.be/embedded-document-with-voyage-in-mongodb
The model in that article has a one-to-many relation between a Spaceship and Pilots. The Pilot isPersistent/isRoot, so has its own MongoDB collection. IIUC, if Pilot were not persistent/root, then the collection of pilots would be serialized along with the Spaceship object, and there would be no separate Pilot collection in MongeDB.
So my question is, how does MongoTalk handle the editing of the pilot collection, when it's embedded into the Spaceship. For example, if a pilot is added, removed, or updated, does the entire embedded collection get re-saved, or does a suitable MongoDB update query get generated?
On 26/11/12 12:14 PM, Esteban Lorenzano wrote:
MontoTalk does not handle it. Voyage does :)
but... an "embedded collection" sounds strange to me... I don't really think that is correct. There is no such thing like embedded collection in a mongodb sense (If I'm understanding right you question).
Sorry, bad choice of wording. I meant a Smalltalk collection, not a mongodb collection. The Spaceship/Pilot example was misleading as well. A better example could be something like a medication schedule with a list of times to have the medication. The list is an array (I think that term will work for Smalltalk and mongodb). It seems unnecessary to normalize the times into a separate collection. So the question is: would Voyage or MongoTalk rewrite the entire array of times on every add, remove, update of a time?
On Nov 26, 2012, at 10:40 PM, Yanni Chiu <yanni@rogers.com> wrote:
On 26/11/12 12:14 PM, Esteban Lorenzano wrote:
MontoTalk does not handle it. Voyage does :)
but... an "embedded collection" sounds strange to me... I don't really think that is correct. There is no such thing like embedded collection in a mongodb sense (If I'm understanding right you question).
Sorry, bad choice of wording. I meant a Smalltalk collection, not a mongodb collection. The Spaceship/Pilot example was misleading as well.
A better example could be something like a medication schedule with a list of times to have the medication. The list is an array (I think that term will work for Smalltalk and mongodb). It seems unnecessary to normalize the times into a separate collection. So the question is: would Voyage or MongoTalk rewrite the entire array of times on every add, remove, update of a time?
yes, MongoTalk (and Voyage because of that) will re-write the full document (that's how the driver works: is document-atomic)
participants (3)
-
Esteban Lorenzano -
Fernando Olivero -
Yanni Chiu