genghis
genghis copied to clipboard
Limit fields returned from query?
First off, fantasitc app! Second, I apologize in advance if this capability exists already and it is escaping me: is it possible to use Mongo's projection feature to limit the fields returned from a query? For example, in the CLI I might write:
db.collection.find({ year: 1586, type: 'prent'}, { maker: 1, title: 1})
in order to return query results with just the maker
and title
fields (and the _id
field by default, of course.)
While I get lovely results putting { year: 1586, type: 'prent'}
into the Genghis search field, { year: 1586, type: 'prent'}, { maker: 1, title: 1}
gets rejected. Is there another way to do this? Is this not possible using Genghis?
It's not (yet) possible in Genghis. Projection documents are a planned feature for the next major release.
Thanks for your swift response; that is good to know.
We'll leave this issue open as a feature request reminder :)
:thumbsup:
@mdlincoln @mrdziuban Hey! I just pushed projection support in the develop
branch! You should go try it out :)
It's currently only implemented in the API (i.e. there's no UI for it yet) but you can get to it by hacking on the URL manually, e.g.
Given this collection:
.../collections/cohesive
… set the projection by adding a fields parameter to its documents url:
.../collections/cohesive/documents?fields={twitter:1,email:1}
Note that pagination and searching are a bit wonky on the develop
branch due to a bug in the current version of Backbone. It'll be fixed in their next release, but until then, if you're going to use the develop
branch, you have to manually edit pagination in the URL, and you need to click out of a collection and back in if you want to search a second time.
pulled the development version and tried to specify fields.. no bueno.
http://mdb.???/genghis.php/servers/localhost/databases/by/collections/video?fields={title:1}
Note the URL: .../collections/foo/documents?fields=...
Just like with pagination, it needs the documents
in there, otherwise you're trying to specify fields
on the collection itself, not on the cursor returned by querying the collection :)
@bobthecow thanks that did it.. i assumed adding documents wouldn't work since by itself it redirects.. so whats the latest and getting this into the search box? say something like:
{'categories':{'$in':['g']}}, {title:1}
just like how the project criteria is specified
It probably won't be that. I'm thinking there will be dedicated UI for it in the advanced search form, but I haven't figured out exactly how that will play out yet.
Why not follow the methodology of the CLI? This way it'd be easier for mongo people to guess how this would work instead of figuring it out?