Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Java: Bug in advanced queries
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
shiraz  
View profile  
 More options Nov 3 2011, 8:19 am
From: shiraz <shiraz.li...@googlemail.com>
Date: Thu, 3 Nov 2011 05:19:56 -0700 (PDT)
Local: Thurs, Nov 3 2011 8:19 am
Subject: Java: Bug in advanced queries
hi,

I cannot get the expected results while using the advanced queries
with $and and $not operators

There are 50 of such documents in the mongodb
{ "ServiceType" : "sms" , "ServiceHealthState" : "ok"}

and 50 of
{ "ServiceType" : "jms" , "ServiceHealthState" : "critical"}

The following $and query should return the 50 records:
{"$and":[{"ServiceType":"sms"},{"ServiceHealthState":"ok"}]}

The above query returns 0 results, however the expected result count
should be 50

Likewise for the $not query
{"$not":{"Service_Endpoint_HealthState":"ok"}}

returns 0 results, the required count is 50

Surprisingly $or queries behaves correctly.

System:
The mongodb version is 1.8.3
java driver version 2.6.5

Thanks in advance,
Shiraz


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc  
View profile  
 More options Nov 3 2011, 11:51 am
From: Marc <m...@10gen.com>
Date: Thu, 3 Nov 2011 08:51:30 -0700 (PDT)
Local: Thurs, Nov 3 2011 11:51 am
Subject: Re: Java: Bug in advanced queries
$and is a (relatively) new feature, released in MongoDB version 2.0.
It is not available in 1.8.

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-...

In order for your query to work, you must upgrade.

If upgrading is not possible for you at this time, 'and' queries were
implicit in versions 1.8 and below.

> db.services.save({ "ServiceType" : "sms" , "ServiceHealthState" : "ok"} )
> db.services.save({ "ServiceType" : "jms" , "ServiceHealthState" : "critical"})
> db.services.find({"ServiceType":"sms", "ServiceHealthState":"ok"})

{ "_id" : ObjectId("4eb2b1e43cf8b03f69a2fa0c"), "ServiceType" : "sms",
"ServiceHealthState" : "ok" }

If you upgrade to the latest version of MongoDB, $and will work as
advertised:

> db.version()
2.0.1
> db.services.find()

{ "_id" : ObjectId("4eb2b1e43cf8b03f69a2fa0c"), "ServiceType" : "sms",
"ServiceHealthState" : "ok" }
{ "_id" : ObjectId("4eb2b1f13cf8b03f69a2fa0d"), "ServiceType" : "jms",
"ServiceHealthState" : "critical" }
> db.services.find({$and:[{"ServiceType":"sms"}, {"ServiceHealthState":"ok"}]})

{ "_id" : ObjectId("4eb2b1e43cf8b03f69a2fa0c"), "ServiceType" : "sms",
"ServiceHealthState" : "ok" }

The Mongo documentation on the $not operator states that, "The $not
meta operator can be used to negate the check performed by a standard
operator."  There are some examples in the documentation of how the
$not operator is used.

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-...

If you would like to return all all of the documents in which the key
"ServiceHealthState" is not equal to "ok", the "$ne" (not equal)
operator should be used.

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-...

> db.services.find({"ServiceHealthState":{$ne:"ok"}})

{ "_id" : ObjectId("4eb2b1f13cf8b03f69a2fa0d"), "ServiceType" : "jms",
"ServiceHealthState" : "critical" }

Hopefully the above examples will do what you were hoping to
accomplish.

Good Luck!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
لسٹ शिराज़  
View profile   Translate to Translated (View Original)
 More options Nov 3 2011, 12:07 pm
From: لسٹ शिराज़ <shiraz.li...@googlemail.com>
Date: Thu, 3 Nov 2011 17:07:08 +0100
Local: Thurs, Nov 3 2011 12:07 pm
Subject: Re: [mongodb-user] Re: Java: Bug in advanced queries

Many Thanks Marc, I will then try to upgrade to 2.0.1 manually, as the
latest available mongodb on the suse repository is 1.8.3

http://software.opensuse.org/search?q=mongodb&baseproject=openSUSE%3A...

Best regards,
Shiraz

--
Cheers,
Shiraz

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options Nov 3 2011, 12:13 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Thu, 3 Nov 2011 12:13:23 -0400
Local: Thurs, Nov 3 2011 12:13 pm
Subject: Re: [mongodb-user] Re: Java: Bug in advanced queries
For your query you do not need $and.

2011/11/3 لسٹ शिराज़ <shiraz.li...@googlemail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdahlman  
View profile  
 More options Nov 4 2011, 2:15 am
From: mdahlman <matt.dahl...@gmail.com>
Date: Thu, 3 Nov 2011 23:15:24 -0700 (PDT)
Local: Fri, Nov 4 2011 2:15 am
Subject: Re: Java: Bug in advanced queries
Scott, it's obvious once you mentioned it. Filtering on multiple
fields does not require the use of $and, so it's fine in pre-2.0
MongoDB. I haven't used $and yet. I see why $and is needed with
multikeys. Are there cases where it's useful outside of multikeys?
Shiraz, I hope you don't mind: I used your idea in a sample report to
make sure that things worked the way I expected them to work. I posted
my report showing the multi-field filter here:http://
mdahlman.wordpress.com/2011/11/03/mongodb-multi-field-filter/
Regards,Matt
On Nov 3, 9:13 am, Scott Hernandez <scotthernan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc  
View profile  
 More options Nov 9 2011, 1:43 pm
From: Marc <m...@10gen.com>
Date: Wed, 9 Nov 2011 10:43:37 -0800 (PST)
Local: Wed, Nov 9 2011 1:43 pm
Subject: Re: Java: Bug in advanced queries
There are many cases when $and is useful.  In a nutshell (from the
feature request) "Condition blocks are physically objects. Thus, we
cannot have the same property used twice, preventing the use of the
same construct/property multiple times in a query."
There are several examples of use cases for $and in the Jira
ticket: https://jira.mongodb.org/browse/SERVER-1089

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »