Hi Norbert,

I didn't want to use "use database" for queries but for defining the index
from within smalltalk. But if creating indexes is not supported, I will set
the indexes within the mongo console.

The explain option is very helpful I did not know this.

Your answer was very helpful for me, thanks a lot!
Sabine



2015-08-04 10:42 GMT+02:00 NorbertHartl [via Smalltalk] <
ml-node+s1294792n4840888...@n4.nabble.com>:

> Sabine,
>
> Am 04.08.2015 um 07:08 schrieb Sabine Manaa <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4840888&i=0>>:
>
> Hi,
>
> I have 2 questions concerning use of mongoDB classes:
> 1) how can I send mongo console commands directly from smalltalk
> 2) how to query on an embedded collection with an index
>
> Model:
> I have trips and each trip has an embedded collection of N receipts like
> this:
> { "tripName" : "trip 1",
> {"receipts" : [
> {"receiptDescription" : "receipt 1" }
> {"receiptDescription" : "receipt 2" }
> {"receiptDescription" : "receipt 3" } ],
> }
>
> Index:
> For quick search, I created an index on the embeded[1] receipts with this
> command at the mongoDB console in a terminal (NOT in smalltalk)
> (mongo console starts with mongo in the MongoDB/bin dir):
>
> db.Trips.createIndex({"receipts.receiptDescription":1})
>
> with a command like this in the mongoDB console
>
> db.Trips.find({"receipts.receiptDescription":"receipt 1"})
>
> I get the resulting receipt.
>
> Before, I have to set the database with "use {databasename}" in thr mongodb
> console
>
> My questions:
> 1) how can I send mongo console commands directly from smalltalk, e.g. use
> database, set index etc.
>
>
> I don't know why you want to use "use database". For queries you don't
> need this because you choose the database and collection by using the
> smalltalk classes. You can look there if something you need exists.
> Creating indexes is not yet supported. I want to do that myself. As always
> there seems to be to less people implementing stuff like that.
>
> Is this possible?
> I did not succeed with the mongo command: method, it always returns "no
> such
> cmd".
>
> 2) how can I search for a receipt which is indexed as described from
> smalltalk?
>
>
> A simple
>
> Trip selectMany: { 'receipts.receiptDescription' -> 'Tankquittung' }
> asDictionary
>
> should do. You can use just the nested properties form. The index will be
> selected automatically. If you are not sure about queries read about
> explain [1] to optimize that stuff.
>
> [1]
> http://docs.mongodb.org/manual/reference/method/cursor.explain/#cursor.explain
>
> Norbert
>
>
> I did not succeed with the description [2] I am not sure if it is covered
> by
> it.
>
> Regards
> Sabine
>
>
> [1]
>
> http://docs.mongodb.org/manual/core/index-multikey/#index-arrays-with-embedded-documents
> [2] http://smallworks.eu/web/blog/2013-07-18-Voyage-advanced-queries
>
>
>
> --
> View this message in context:
> http://forum.world.st/MongoDB-console-commands-query-embedded-indexed-fields-tp4840882.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://forum.world.st/MongoDB-console-commands-query-embedded-indexed-fields-tp4840882p4840888.html
> To start a new topic under Pharo Smalltalk Users, email
> ml-node+s1294792n1310670...@n4.nabble.com
> To unsubscribe from MongoDB: console commands? query embedded indexed
> fields?, click here
> <http://forum.world.st/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4840882&code=bWFuYWEuc2FiaW5lQGdtYWlsLmNvbXw0ODQwODgyfC0xOTE3OTcxOTg5>
> .
> NAML
> <http://forum.world.st/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://forum.world.st/MongoDB-console-commands-query-embedded-indexed-fields-tp4840882p4840920.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to