-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fazt
committed
Dec 4, 2017
1 parent
81d97ed
commit 65dd4d3
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// the client is the mongo shell | ||
|
||
// to watch all databases | ||
show dbs | ||
|
||
// to see current databse selected | ||
db | ||
|
||
// to select or create a database | ||
use mivirtualstore | ||
|
||
// CRUD OPERATIONS | ||
// TO CREATE | ||
|
||
const post = { | ||
"title": "My first Post", | ||
"content": "Here is my blog post", | ||
"date": new Date() | ||
} | ||
// this generates an _id | ||
db.blog.insert(post) // WriteResult({ "nInserted" : 1 }) | ||
|
||
// TO READ | ||
db.posts.find() // to query all collections | ||
db.posts.findOne() // to query a single collection | ||
|
||
// TO UPDATE | ||
// we need (criteria, newDocument) | ||
const myNewPost = db.posts.findOne() | ||
myNewPost.comments = []; | ||
db.posts.update( | ||
{_id: ObjectId("5a2490f249c2a502853b7e7a")}, | ||
myNewPost | ||
) // this add comments: [] | ||
|
||
// TO REMOVE | ||
db.posts.remove({title: "My first Post"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# Course | ||
- document/ | ||
- collections/ | ||
- shell/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// to start the shell: mongo | ||
|
||
// the shell can be execute javascript | ||
x = 200; | ||
x / 5; | ||
|
||
// and we can use the standard javascript libraries | ||
Math.sin(Math.PI / 2) | ||
|
||
new Date("2018/1/1") | ||
|
||
"Hello World".replace("World, Mongodb"); | ||
|
||
// and we can define functions | ||
function factorial(n) { | ||
if (n <= 1) return 1; | ||
return n * factorial(n - 1); | ||
} | ||
|
||
const double = n => n * 2; | ||
|
||
// and the shell also recongnise incomplete statments with ENTER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters