mongodb - mongo $ne query with an array not working as expected -


i'm trying run following queries data inserted follows. whatever reason $ne 0 in value doesn't seem work. tried on both linux , mac using v2.0.4. ran these using mongo shell.

anybody have ideas? bug or i'm misunderstanding?

db.associated.insert({     "diskinfo" : {             "physical" : [                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 509"}             ]     }})  db.associated.insert({     "diskinfo" : {             "physical" : [                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 5"},                     {"merror_count" : "count: 0"}             ]     }})  db.associated.insert({     "diskinfo" : {             "physical" : [                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 0"},                     {"merror_count" : "count: 0"}             ]     }}) 

ran these queries on mongo shell. , got results in comments

 db.associated.find( { "diskinfo.physical.merror_count" : { $ne : 'count: 0'}}).count() //  result: 0, expected: 2 db.associated.find( { "diskinfo.physical.merror_count" : { $ne : 'count: 509'}}).count() // result: 2, expected: 2 db.associated.find( { "diskinfo.physical.merror_count" : { $ne : 'count: 5'}}).count() // result: 2, expected: 2 

these results correct.

your expectation may based on number of elements in embedded array match predicate. however, it's number of documents satisfy query getting back.

in first case query documents don't have diskinfo.physical.merror_count equal 'count: 0'. every document has diskinfo.physical.merror_count that's 'count: 0' 0.

look @ way, every document in collection has diskinfo.physical.merror_count value that's other 'count: 0'. if queried equality instead of inequality three.

are trying find documents have only entries 'count: 0'?

there doesn't seem straight forward way this, 1 query be:

db.associated.find( { "diskinfo.physical.merror_count" : { $gt : 'count: 0'}}).count()

at least solution if counts integers - happens work strings because "1">"0", etc.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

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

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