MongoDB Module: maps → strings?

4 views
Skip to first unread message

Christian Grün

unread,
Mar 25, 2015, 7:38:42 PM3/25/15
to EXPath, EXPath
Dear EXPath followers,

Thanks for the feedback on our MongoDB module [1]! The general
reactions on the current working draft were all positive, but we
stumbled upon a potential show stopper:

In our module, we initially decided to use XQuery maps and arrays for
representing JSON structures. Unfortunately, it turned out there are
at least some MongoDB functions – such as mongo:command – that require
map entries to be ordered (!). However, map entries in XQuery have no
order, which means that we need to rethink our current design. We
currently see the following alternatives:

1. Use JSON strings, as proposed in Dannes' initial Mongrel implementation,
2. Use XML representations of JSON structures, such as the one
generated via fn:json-to-xml,
3. Ensure order of map entries by wrapping them in additional
sequences or arrays.

We are currently trying to find out which fallback causes least
headache, but we are also interested in your thoughts. Let us know
what you think!

Christian

[1] http://expath.org/spec/mongo

Adam Retter

unread,
Mar 26, 2015, 5:36:56 AM3/26/15
to exp...@googlegroups.com, EXPath
Maps are defined as functions, so why not just use functions for this
to create an ordered map? Or just place k->v functions into an array?
> --
> You received this message because you are subscribed to the Google Groups "EXPath" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to expath+un...@googlegroups.com.
> To post to this group, send email to exp...@googlegroups.com.
> Visit this group at http://groups.google.com/group/expath.
> For more options, visit https://groups.google.com/d/optout.



--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

Christian Grün

unread,
Mar 26, 2015, 6:27:24 AM3/26/15
to EXPath, EXPath
Hi Adam,

Thanks for your feedback.

> Maps are defined as functions, so why not just use functions for this
> to create an ordered map? Or just place k->v functions into an array?

I can't figure out yet how this would look like. Could you give a small example?

This was the map syntax we wanted to use:

mongo:command($id, 'db', map {
"createIndexes": "coll",
"indexes": "..."
})

The string fallback would look like this:

mongo:command($id, 'db', '{
"createIndexes": "coll",
"indexes": "..."
}')

Best,
Christian

Adam Retter

unread,
Mar 26, 2015, 6:53:44 AM3/26/15
to exp...@googlegroups.com, EXPath
mongo:command($id, 'db', (
function() {('createIndexes', 'coll')},
function() {('indexes', '...')}
))

Basically instead of using a map of key-value pairs (which is just a
function from key->value), you use an array/sequence (which is
ordered) of functions which return key->value pairs. You could model
this in several different ways, for example another way would be:

mongo:command($id, 'db', function() {
array {
('createIndexes', 'indexes'),
function($key as xs:string) {
switch($key) {
case 'createIndexes':
'coll'
case 'indexes':
...
}
}
}
})

I would abstract this structural pattern and provide functions to help
create it, as you will be nesting this to be able to create
effectively ordered maps of maps.

Although.... it might just be easier to use XML! :-)

Christian Grün

unread,
Mar 26, 2015, 8:02:36 AM3/26/15
to EXPath, EXPath
Got it! Thanks.

I have some fears that a too verbose representation might prevent
people from working with the module. We are currently experimenting
with different representations.

Personally, I more and more tend to the plain string representation.
If someone wants to have better typing, it's still possible to use
existing JSON mappings before eventually calling the MongoDB
functions.

We will keee you updated,
Christian

Hans-Juergen Rennau

unread,
Mar 26, 2015, 8:35:46 AM3/26/15
to exp...@googlegroups.com, EXPath
Yes, Adam, I think XML would be easier. So it seems to me the chief candidates for representing JSON structures within function signatures are (a) a serialized JSON string, favoured by Christian, or (b) an XML equivalent.

Cheers,
Hans-Jürgen




--
You received this message because you are subscribed to the Google Groups "EXPath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to expath+unsub...@googlegroups.com.

Adam Retter

unread,
Mar 26, 2015, 8:44:38 AM3/26/15
to exp...@googlegroups.com, EXPath
I don't think the serialized string representation of JSON would solve
your problem. If you take a Map in XQuery 3.1 and serialize it, you
have no guarantee what order the serialization will produce the keys
in (unless I am mistaken)?

On 26 March 2015 at 12:35, 'Hans-Juergen Rennau' via EXPath
> email to expath+un...@googlegroups.com.
> To post to this group, send email to exp...@googlegroups.com.
> Visit this group at http://groups.google.com/group/expath.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "EXPath" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to expath+un...@googlegroups.com.
> To post to this group, send email to exp...@googlegroups.com.
> Visit this group at http://groups.google.com/group/expath.
> For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages