Chaining queries with pymongo - mongodb

So, I'm currently trying to make an extensible wrapper for pymongo and I found myself wishing that it was possible to query a cursor. This is mostly for making the api as clean as possible. Basically what I was imagining was something along these lines:
def get_all_x_type(collection):
return collection.find({"type":"x"})
def get_all_y_kind(collection):
return collection.find({"kind": "y"})
def get_all_x_and_y(collection):
return get_all_x(get_all_y(collection))
Implementation details are actually nicer than that, but that's the general functionality I'm looking for. I know it's possible to just extend the find query, but I would like to be able to deal with cursors passed to me from other people. Is there any way to do something like this? I could checks on the cursor as I iterate through it, but that seems pretty gross and I was looking for something a bit cleaner.
Alternately is this a silly idea for some reason? I'm not a mongo expert by any means, but this functionality seemed useful to me, but it might just be my naivete.

Related

RxJava Observable join() what is a good use case

im searching for a good example easy to understand on what the join command really does.
it seems its similar to other combined functions like zip or combineLatest perhaps but it mentions having a window of time that it can join... can anyone give a real world example of how to use it ?
i tried so far something like this:
Observable.just(1,2,3).join(Observable.just(4,5,6,7))
but this does not compile.its asking for a leftEnd and a rightEnd functions. but i'm confused what i need to do here and the documentation is a bit confusing.

Why does it appear that json4s JObject uses a List(Tuple2) under the hood

This is really bad if it is what I think it is. I'm still learning Scala so I could be missing something HUGE but if I need constant time access to a specific element in a JObject, wouldn't storing the elements as a List(Tuple2) be REALLY REALLY REALLY bad for runtime?
I'm working on an application which uses Spark... and it looks like Spark is using json4s. I could imagine there's a good reasoning behind this, or maybe I don't know enough about Scala yet to understand why this doesn't matter.
Any thoughts?

Canonical list of scala 'operators'

It seems easy to find general info on a specific 'operator' (method, syntactic sugar), but I can't seem to find anything that has a list of all, or even just most, of these goodies. As such, it makes it fairly difficult, or at least overly time consuming, to work through learning the language.
I have already looked over this question. While it has great information, and definitely shows you how to find any information you need, I was hoping for something like a 'pocket ref' that just had all the relevant info and was only dedicated to that.
So, my question is this:
Is there a such a list?
Am I getting ahead of myself by looking for such a reference early on in learning the language?
Thanks in advance.
Well, a list of all operators makes as much sense as a list of all methods in the library, regardless of the type. It isn't going to be particularly useful except for finding information about a specific operator.
However, if you do want one, at any ScalaDoc site (http://www.scala-lang.org/api/current/ for the standard library) there is an alphabetic index just under the search bar. The first link (#) lists all the non-alphabetic methods (i.e. "operators").
Many of these are rarely used, or only in specific circumstances.
Obviously, any other library can introduce its own operators, and you'll need to check its own documentation.

Looking for example of dojo.store with dijit.Tree over REST

I'm looking for an end to end example using dojo.store with dijit.Tree over REST.
There are many existing examples that use the older dojo api, dojo.data.api, but a dearth of ones using the dojo.store api.
Is the reason that dijit.Tree doesn't fully support dojo.store yet?
If so, do I need to use the dojo.data.ObjectStore wrapper to encapsulate dojo.store for use with dijit.tree?
I saw one example of working around this by extending StoreFileCache:
http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-td2680201.html
Is that the recommended option, or should I
a) stick to dojo.data.api until dijit.Tree supports dojo.store directly, or
b) use the dojo.data.ObjectStore wrapper
Thanks
There is now a tutorial on the DTK website that seems to cover pretty much exactly this topic.
http://staging.dojotoolkit.org/documentation/tutorials/1.6/store_driven_tree/
However, as I know linking to something without giving an answer is considered a poor practice, the general idea is that rather than using a dojo.data.ObjectStore to wrap around it and then potentially shoving it through a ForestStoreModel, you can simply augment your dojo.store-based store to add the methods that the Tree will look for. Here's a simple example from the tutorial:
usGov = new dojo.store.JsonRest({
target:"data/",
mayHaveChildren: function(object){
// see if it has a children property
return "children" in object;
},
getChildren: function(object, onComplete, onError){
// retrieve the full copy of the object
this.get(object.id).then(function(fullObject){
// copy to the original object so it has the children array as well.
object.children = fullObject.children;
// now that full object, we should have an array of children
onComplete(fullObject.children);
}, onError);
},
getRoot: function(onItem, onError){
// get the root object, we will do a get() and callback the result
this.get("root").then(onItem, onError);
},
getLabel: function(object){
// just get the name
return object.name;
}
});
It's worth noting that in this case, we're making some assumptions about what the data looks like. You'd need to know how your children relate and customize the methods below for that purpose, but it's hopefully fairly clear as to how to do that for yourself.
You can also just stick to dojo.data APIs for now, but this approach definitely feels more lightweight. It takes a couple of layers out of the stack and working with customizing a dojo.store-based store is much easier.
Given the two options you outlined, I'd say it's a matter of how well you know the different APIs.
dojo.store is more light-weight, and perhaps easier to understand, but the wrapper adds some overhead. If you think your project will live for a long time, this is probably the best way to go.
dojo.data is a legacy API, which will phased out eventually. If your project is short-lived, and only based on dijit.Tree, this might be your best option for now.
Personally, I'd go with dojo.store and write my own TreeStoreModel to get the best of both worlds. This approach is very similar to Brian's suggestion.
In case you're interested, I've written up a two-series post on how to use dijit.Tree with the ObjectStore wrapper, and implementing a JsonRest backend in PHP.

Autogenerated keys in Pilog

What's the best way to go about autogenerated keys for Pilog? i've
been digging around a bit and can't find anything related.
Hints and pointers would be most appreciated. Thank you.
You get the same behavior as auto increment in for instance MySQL with this
one: http://software-lab.de/doc/refG.html#genKey
I use it a lot in the VizReader code.
I'm not so sure I would've used it much though if I had know about the (id)
function from the start: http://software-lab.de/doc/refI.html#id
In my case it's all about displaying a nice id that is easy to relate for
humans and JavaScript in my non-traditional gui and as you can see both
approaches accomplish that but that latter is imo more elegant.
/Henrik Sarvell
(Copied verbatim form Henrik Sarvells' answer.)