Query operations under MongoDB (corresponding to Java API query operations)

Source: Internet
Author: User

Related reading:

Install and start MongoDB in Linux

Advanced query example in MongoDB

MongoDB Java API for insert and single collection basic query examples

Query operations under MongoDB (corresponding to Java API query operations)

[Root @ localhost ~] # Mongo
MongoDB shell version: 1.8.1
Connecting to: test
> Db
Test
> Show collections
Data_test
System. indexes
System. users
> Db. system. users. find ()
{"_ Id": ObjectId ("4dd73c7d247cb75e4995757b"), "user": "iwtxokhtd", "readOnly": false, "pwd": "success "}
> Db. data_test.find ()
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30"), "userId": "10010171", "userName": "Bill Tu1", "gender": "m1 ", "interests": {"game": "game1", "ball": "ball1", "other": "nothing1 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a31"), "userId": "10010172", "userName": "Bill Tu2", "gender": "m2 ", "interests": {"game": "game2", "ball": "ball2", "other": "nothing2 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a32"), "userId": "10010173", "userName": "Bill Tu3", "gender": "m3 ", "interests": {"game": "game3", "ball": "ball3", "other": "nothing3 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a33"), "userId": "10010174", "userName": "Bill Tu4", "gender": "m4 ", "interests": {"game": "game4", "ball": "ball4", "other": "nothing4 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a34"), "userId": "10010175", "userName": "Bill Tu5", "gender": "m5 ", "interests": {"game": "game5", "ball": "ball5", "other": "nothing5 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a35"), "userId": "10010176", "userName": "Bill Tu6", "gender": "m6 ", "interests": {"game": "game6", "ball": "ball6", "other": "nothing6 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a36"), "userId": "10010177", "userName": "Bill Tu7", "gender": "m7 ", "interests": {"game": "game7", "ball": "ball7", "other": "nothing7 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a37"), "userId": "10010178", "userName": "Bill Tu8", "gender": "m8 ", "interests": {"game": "game8", "ball": "ball8", "other": "nothing8 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a38"), "userId": "10010179", "userName": "Bill Tu9", "gender": "m9 ", "interests": {"game": "game9", "ball": "ball9", "other": "nothing9 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a39"), "userId": "100101710", "userName": "Bill Tu10", "gender": "m10 ", "interests": {"game": "game10", "ball": "ball10", "other": "nothing10 "}}
> Db. data_test.findOne ()
{
"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30 "),
"UserId": "10010171 ",
"UserName": "Bill Tu1 ",
"Gender": "m1 ",
"Interests ":{
"Game": "game1 ",
"Ball": "ball1 ",
"Other": "nothing1"
}
}
> Db. data_test.find ({"userId": "10010171 "})
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30"), "userId": "10010171", "userName": "Bill Tu1", "gender": "m1 ", "interests": {"game": "game1", "ball": "ball1", "other": "nothing1 "}}
> Db. data_test.find ({"userId": "10010171", "userName": "Bill Tu1 "})
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30"), "userId": "10010171", "userName": "Bill Tu1", "gender": "m1 ", "interests": {"game": "game1", "ball": "ball1", "other": "nothing1 "}}
> Db. data_test.find ({"userId": {$ in: ["10010171", "10010172"]})
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30"), "userId": "10010171", "userName": "Bill Tu1", "gender": "m1 ", "interests": {"game": "game1", "ball": "ball1", "other": "nothing1 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a31"), "userId": "10010172", "userName": "Bill Tu2", "gender": "m2 ", "interests": {"game": "game2", "ball": "ball2", "other": "nothing2 "}}
> Db. data_test.find ({"userId":/10010171. */I })
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a30"), "userId": "10010171", "userName": "Bill Tu1", "gender": "m1 ", "interests": {"game": "game1", "ball": "ball1", "other": "nothing1 "}}
{"_ Id": ObjectId ("4dd747cb3a491e68a1a84a39"), "userId": "100101710", "userName": "Bill Tu10", "gender": "m10 ", "interests": {"game": "game10", "ball": "ball10", "other": "nothing10 "}}
>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.