advanced queuing - mongodb query without field name -


i query objects have field containing specific value. example, have 2 documents:

{"123": "apple", "217": "pear", "179": "orange"} {"831": "pear", "189": "grapes"} 

and objects has field value "apple", not know name of field. possible specify query in mongodb achieve this? (the numerical keys in objects children ids, , values in objects long guids)

unfortunately, mongodb not support method of querying fields particular value. there existing jira ticket requesting enhancement: https://jira.mongodb.org/browse/server-1248 . feel free comment, vote, or follow ticket.

in meantime, usual way handled change mongodb schema. example, change existing schema:

{"123": "apple", "217": "pear", "179": "orange"}  {"831": "pear", "189": "grapes"}  

and might structure this:

 { tags: [         { cid: "123", value: "apple" },         { cid: "217", value: "pear" },         { cid: "179", value: "orange" },       ]     }    { tags: [         { cid: "831", value: "pear" },         { cid: "189", value: "grapes" },       ]     } 

once you've done this, can perform follwing query find of desired documents:

 db.docs.find( {'tags.value': "apple" } ) 

note schema allows index 'tags.cid' , 'tags.value' fields, original schema not.

i hope helps.

-william


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -