I need to know how to use where
in MongoDB queries using Java Driver.
SELECT COLUMN1, COLUMN2 WHERE COLOUM3 = 'KeyWord';
I have a key Name and its value, and i want to find some other key/value. I think i can use $where
for that. But, i dont know its syntax in java.
How shall i use where
in my mongo queries?
Any suggestions would be appreciative!!!!
Thanks!
You shouldn't generally need to use $where ...
You should be using the "document-style query" find()
Basically find() is MongoDB's version of where ...
If you have a collection called mycollection and a attribute called attribute1 (this is exactly like your COLUMN1 )
So to get results like this SQL query ...
SELECT * WHERE COLOUM3 = 'KeyWord';
Via the MongoDB shell, you'd use find() like so ...
> db.mycollection.find({attribute1:"KeyWord"})
You really shouldn't need to use $where for most any normal mongodb query.
Lots more help here: http://www.mongodb.org/display/DOCS/Querying
There is a site called www.querymongo.com that translates SQL syntax into MongoDB syntax. It's really useful for cases like this.
In the case of the example above:
SQL:
SELECT * FROM collection WHERE COLOUM3 = 'KeyWord';
Becomes this in MongoDB:
db.collection.find({
"COLOUM3": "KeyWord"
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.