bobthecow / genghis

The single-file MongoDB admin app
http://genghisapp.com
MIT License
1.45k stars 165 forks source link

Limit fields returned from query? #159

Open mdlincoln opened 10 years ago

mdlincoln commented 10 years ago

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?

bobthecow commented 10 years ago

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

mdlincoln commented 10 years ago

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

bobthecow commented 10 years ago

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

mdlincoln commented 10 years ago

:thumbsup:

bobthecow commented 10 years ago

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

acidjazz commented 10 years ago

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

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

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 :)

acidjazz commented 10 years ago

@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

bobthecow commented 10 years ago

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.

acidjazz commented 10 years ago

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?