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