Water Test MongoDB

Source: Internet
Author: User
Tags findone

1) Start MongoDB service after installation.

1_1) Establish data/db to ensure that at least 3g of disk size

1_2) Create a log folder

1_3) configuration file

Content, specifying where the data is stored, the log file location

Dbpath=f:\mongodb\data\db

Logpath=f:\mongodb\log\mongo.log

1_3) Specify the database path

CD/D F:mongdb/bin

Mongod--dbpath=d:\mongodb\data\db

1_4) Open

CD/D F:mongdb/bin

Mongo

2) connection

CD/D F:mongdb/bin

Mongo

To see if the success is turned on:

localhost:27017

3) Create user

Db.adduser ("UserName", "Passwork", True)

4) Robomongo Login Local Mango

localhost:27017

Username:wgr

Passwork:wgr123

Db:test

5) Inserting data

Var single ={"name": "WGR", "Address": "Guangzhou Longgui", "favourate" ["Apple", "Banana"]}

Db.user.insert (Single)

6) View:

Learning Address:

Http://www.cnblogs.com/think_fish/p/3422307.html

6_1)equals

Db.user.find ({"Name": "WGR"})

6_2)Greater than

Db.user.find ({"Age": {$gt: 30}})

3XVNNot equal to

$ne Not equal to noe equals

Db.collection.find ({age:{$ne:});// Age not equal to

6_4)verifies whether an element exists

This syntax is a bit around

Db.collection.find ({title:{$exists: true}); if the record has All returns that contain the title attribute

Db.collection.find ({title:{$exists: false}}); If the record contains All of the title property does not return, does not contain all return of the title property

6_5) Regular Expressions

Db.user.find ({"Name":/w/i})

MONGO supports regular expressions, such as:

Db.customers.find ({name:/acme.*corp/i}); The meaning of the latter i is case-sensitive

Support for regular expression queries makes mongdb A fairly powerful query, but it also requires developers to learn more about regular Expressions

6_6 "Query the values within the data

The query below is query colors red colors element is a data Span style= "FONT-FAMILY:CALIBRI;" >, db.things.find ( { colors :  "Red"  } );

6_7 $elemMatch

If an object has an element that is an array, then $elemMatch

> t.find ( { x : {  $elemMatch  : { a  : 1, b : {  $gt  : 1 } } } } )  


{"_id": ObjectId ("4b5783300334000000000aa9"),
"X": [{"A": 1, "B": 3}, 7, {"B": [+]}, {"A": 11}]
} $elemMatch: {a:1, B: {$gt: 1}} all conditions must match.

Note that the above statement is not the same as below.

> T.find ({"X.A": 1, "x.b": {$gt: 1}})
$elemMatch is the match {"A": 1, "B": 3}, and the following sentence is the match {"B": "A", {"A" : one}

Test:

Db.user.find ({"Name":/zhux/i},{"Family.son":/xi/i})

Db.user.find ({"Name":/zhux/i},{"Family.wife":/peng/i},{"Family.son":/xi/i})

6_8)querying the value of an embedded object
Db.postings.find ({"Author.name": "Joe"});

Note that usage is author.name, just use one point. More detailed can see this link: dot notation

As an example:

> Db.blog.save ({title: "My first Post", Author: {Name: "Jane", Id:1}})

If we want to query authors name is Jane , We can do this:

> Db.blog.findOne ({"Author.name": "Jane"})

If not, then you need to use the following sentence to match:

Db.blog.findOne ({"Author": {"name": "Jane", "id": 1}})

The following sentence:

Db.blog.findOne ({"Author": {"name": "Jane"}})

is not matched, because MongoDB for sub-objects, he is exact match.  

6_9)meta operator$notTake counter

Such as:

Db.customers.find ({name: {$not:/acme.*corp/i}});d B.things.find ({A: {$not: {$mod: [10, 1]}});

Test

/*var a={"name": "Zhuxi", "Age": $, "family": {"wife": "Pengliyuan", "Son": "Xiaoli"}}

Db.user.find ({"Name":/zhux/i},{"Family.wife":/peng/i},{"Family.son":/xi/i})

Db.user.insert (a);

var a={"name": "Zhuxi", "Age": $, "detail": [{"Wife1": "Pengliyuan"},{"Son1": "Xiaoli"}]}

Db.user.insert (a);

--The element in the object is a method of checking of elements ( arrays )

Db.user.find ({"Family.wife":/peng/})

"Family":

{

"Wife": "Pengliyuan",

"Son": "Xiaoli"

}

-- The element within the object is a method of multi-element (array) checking

Db.user.find ({"detail": {$elemMatch: {"Wife1":/peng/i}}})

"Detail":

[

{

"Wife1": "Pengliyuan"

},

{

"Son1": "Xiaoli"

}

]

*/

Water Test MongoDB

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.