[MongoDB] Introduce to MongoDB

Source: Internet
Author: User

1. Use or create a database:

Use Wandrecorder

You'll use the keyword to create or fetch a exicting database.

2. Find all documents in the database.

Db.wands.find ()

You already start with DB Keywrod. Then follow your collection name, where is ' wands ', find () method would return all the documents in that collection.

3. Insert document to the collections:

Db.wands.insert ({name: ' Dream Bender ', Creator: ' Foxmond '})

Use Insert () Metod to inserts JSON data to the collection as a document.

4. Find a value in the collections:

Db.wands.find ({name: ' Storm Seeker '})

You can pass the JSON object or Bson an object into the Find method.

http://bsonspec.org/

Result:

{  "_id": ObjectId (' d0a77e57a0544ec7ad5a740b '),  "name": "Storm Seeker",  " Creator ":" Olivemist ",  " level_required ": $,  " price ": 55.99,  " powers " : [    "Wind",    "Static"  ],  "damage": {    "magic" : 2,    "melee": 5  }}

5. The data type not necessary to is array, number or string, they canbe Object, Date also:

Db.wands.insert ({  "name": "Dream Bender",  "creator": "Foxmond",  "Level_ Required ":  ", "Price": 34.9,  "powers": [' Fire ', ' Love '],  ' damage ': {' Magic ": 4," melee ": 2}});

6. Find value in a array:

Db.wands.find ({powers: ' Fire '})

[MongoDB] Introduce to 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.