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
mongodb problems with andoperator
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
  2 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
 
Elisabeth J  
View profile  
 More options Sep 29 2012, 9:42 am
From: Elisabeth J <elisabeth...@gmail.com>
Date: Sat, 29 Sep 2012 06:42:59 -0700 (PDT)
Local: Sat, Sep 29 2012 9:42 am
Subject: mongodb problems with andoperator

I'm trying to create a dynamic mongodb query using spring criteria. My
query is :  Criteria.where(key1).is(value1 .and(key2).is(value2)

If I use it the query works but if I try:

new
Criteria().andOperator(Criteria.where(key1).is(value1),Criteria.where(key2) .is(value2))

It doesn't works. I would want to use the second solutions because the
number of keys and values aren't fixed.

Can someone tell me what's the difference beetween these solutions or where
is the error?

I'll try to create manually the query but it doesn't work:

            BasicDBList andList = new BasicDBList();
            andList.add(new BasicDBObject(key1,value1));
            andList.add(new BasicDBObject(key2,value2));      
           BasicDBObject queryObject = new BasicDBObject("$and", andList);

 but                  
mongoTemplate.getCollection(collectionName).find(queryObject);
 is empty!

Can someone hel me to find errors?

 Thanks too much.


 
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.
Jeremy Mikola  
View profile  
 More options Oct 2 2012, 4:41 pm
From: Jeremy Mikola <jmik...@gmail.com>
Date: Tue, 2 Oct 2012 13:41:59 -0700 (PDT)
Local: Tues, Oct 2 2012 4:41 pm
Subject: Re: mongodb problems with andoperator

You should be able to use the BasicDBObject.toString() method to export the
query as JSON, which you can then copy/paste into the shell. Have you tried
running that outside of the Java application and confirming if it yields
the expected results?

Your second code example looks correct when compared to one of the answers
in http://stackoverflow.com/questions/10444038/mongo-db-query-in-java. The
only difference is that you were using a BasicDBList instead of an
ArrayList in the SO example, which I don't think is reason for concern.


 
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 »