marcelnicolay / mongotor

An asynchronous driver and toolkit for accessing MongoDB in Tornado
Other
57 stars 16 forks source link

cant use positional element (foo.$.bar) #24

Closed abdelouahabb closed 12 years ago

abdelouahabb commented 12 years ago

how to make a positional element query:

this will show only the pup element and not the whole informations

db.users.find_one({"pup.spec.id":id}, {"pup.spec.$.id":1})

marcelnicolay commented 12 years ago

i don't know what you're trying to do, but you can't use position operator '$' in query, you can only use in update.

take a look here: http://stackoverflow.com/questions/6280259/mongodb-use-positional-operator-for-querying

abdelouahabb commented 12 years ago

the positional element here is used to return only the sub document (without using aggregate), so : db.users.find_one({"pup.spec.id":id}) will return the whole subdocument with its parent and other subdocuments. db.users.find_one({"pup.spec.id":id}, {"pup.spec.$.id":1}) will return only the subdocument. it works on pymongo.

abdelouahabb commented 12 years ago

i think it's the same as $elementmatch because it will not loop and returns the first element found?

marcelnicolay commented 12 years ago

okay, i'll try this...

marcelnicolay commented 12 years ago

there was a problem when you call without kwargs:

db.users.find_one({"pup.spec.id":id}, {"pup.spec.$.id":1})

to be work you needed to call with explicit fields: db.users.find_one({"pup.spec.id":id}, fields={"pup.spec.$.id":1})

i fixed this... now you can call without kwargs.

abdelouahabb commented 12 years ago

excellent ;) thank you a lot. catching now works also, thank you :) about gridfs i'm using filesystem + Ngnix ;)