mongo-lite icon indicating copy to clipboard operation
mongo-lite copied to clipboard

How to select specific columns

Open talha-asad opened this issue 13 years ago • 4 comments

I can't select specific columns from the result set. It always continue to return the whole document.

What i mean is if i have a collection with three fields and i only wanted the result set to have all the rows with only one field. It seems impossible to do that.

I tried:

db.users.first({email: "[email protected]"}, {name:1}, function(err, doc) { ... });

However it returns not just name but all the other fields as well. Please tell me if i am doing this incorrectly.

talha-asad avatar Mar 15 '13 08:03 talha-asad

To add further to it doesn't work with first, all or any of the document selection methods. I love this library but just can't get my head around this simple problem, i am guessing i am missing something. Could you please point me in the right direction?

P.S i am using the synchronized version of the api. although i wrote the async example above.

talha-asad avatar Mar 15 '13 22:03 talha-asad

Hi, that's strange, usually it should behave in the same way as native driver. Maybe it's a bug.

Sorry, but I have very tight schedule now, don't have time to investigate it.

al6x avatar Mar 16 '13 19:03 al6x

Hi Alex,

I really appreciate the effort you've put into this already, I don't know coffeescript but i could upload a pull request of the javascript version, if you could point me into the correct direction. Give me a pointer of the function and file i should be looking in.

Thanks alot alex for getting back to me in such short time.

talha-asad avatar Mar 16 '13 19:03 talha-asad

the problem i saw in the query that it performed was that it was adding the fields that i mentioned along with the limit argument, which is wrong. So its probably how you're slicing and passing arguments to the native driver.

mongo: testdb.users.find {"email":"[email protected]"}, {"name":true,"limit":1}

you see the problem ? Its adding the field i want returned in the documents added in the wrong argument. limit and fields required are to be in separate arguments.

I hope that helps.

talha-asad avatar Mar 16 '13 23:03 talha-asad