genghis icon indicating copy to clipboard operation
genghis copied to clipboard

Limit fields returned from query?

Open mdlincoln opened this issue 11 years ago • 10 comments

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?

mdlincoln avatar Jan 12 '14 20:01 mdlincoln

It's not (yet) possible in Genghis. Projection documents are a planned feature for the next major release.

bobthecow avatar Jan 12 '14 21:01 bobthecow

Thanks for your swift response; that is good to know.

mdlincoln avatar Jan 12 '14 21:01 mdlincoln

We'll leave this issue open as a feature request reminder :)

bobthecow avatar Jan 13 '14 02:01 bobthecow

:thumbsup:

mdlincoln avatar Jan 13 '14 19:01 mdlincoln

@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}

projection

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.

bobthecow avatar Jan 18 '14 02:01 bobthecow

pulled the development version and tried to specify fields.. no bueno.

http://mdb.???/genghis.php/servers/localhost/databases/by/collections/video?fields={title:1}

acidjazz avatar Feb 07 '14 02:02 acidjazz

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 avatar Feb 07 '14 02:02 bobthecow

@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

acidjazz avatar Feb 07 '14 02:02 acidjazz

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.

bobthecow avatar Feb 11 '14 05:02 bobthecow

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?

acidjazz avatar Feb 11 '14 22:02 acidjazz