-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
98 changed files
with
2,228 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const inquirer = require('inquirer') | ||
|
||
const promptList = [ | ||
{ | ||
type: 'input', | ||
name: 'userName', | ||
message: 'set a user name:', | ||
default: 'test_user', | ||
// validate: function (val) { | ||
// if (val.length === 3) { | ||
// return val | ||
// } | ||
// return '请输入3位数字.' | ||
// } | ||
}, | ||
{ | ||
type: 'input', | ||
message: '请输入手机号:', | ||
name: 'phone', | ||
validate: function(val) { | ||
if(val.match(/\d{3}/g)) { // 校验位数 | ||
var done = this.async(); | ||
done(null, true) | ||
return val; | ||
} | ||
return "请输入3位数字"; | ||
} | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'test', | ||
message: 'Are you handsome?', | ||
default: true | ||
} | ||
] | ||
|
||
inquirer | ||
.prompt(promptList) | ||
.then(answers => { | ||
console.log('answers:', answers) | ||
console.log('%c answers:', answers, 'font-size: 14px; color: red;') | ||
}) | ||
|
||
// const list = [{ | ||
// type: 'confirm', | ||
// name: 'test', | ||
// message: 'Are you handsome?', | ||
// default: true | ||
// }] | ||
// inquirer.prompt(list).then((answers) => { | ||
// console.log('结果为:'); | ||
// console.log(answers); | ||
// }) |
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,13 @@ | ||
{ | ||
"name": "demo", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"inquirer": "^7.1.0" | ||
} | ||
} |
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,2 @@ | ||
## inquirer.js —— 一个用户与命令行交互的工具 | ||
https://blog.csdn.net/qq_26733915/article/details/80461257 |
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
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,2 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
.idea/* |
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,2 @@ | ||
# MDBAuthedGuideSrc | ||
《MongoDB权威指南(第二版)》源码整理 |
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 @@ | ||
### 第1章 MongoDB简介 |
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,38 @@ | ||
/*** | ||
* CRUD 操作 | ||
***/ | ||
|
||
/*** | ||
* 创建文档 | ||
***/ | ||
post=// | ||
{ | ||
"title":"My Blog Post", | ||
"content":"Here is my blog post.", | ||
"date":ISODate("2012-08-24T21:12:09.982Z") | ||
} | ||
|
||
//插入(创建)新文档 | ||
db.blog.insert(post); | ||
|
||
// 查询集合 blog | ||
db.blog.find(); | ||
|
||
/*** | ||
*查询一条记录 | ||
***/ | ||
db.blog.findOne(); | ||
|
||
/*** | ||
*更新文档 | ||
***/ | ||
// 增加 comments 评论功能 | ||
post.comments=[]; | ||
db.blog.update({title:"My Blog Post"},post); | ||
db.blog.findOne(); | ||
|
||
/*** | ||
*删除文档 | ||
***/ | ||
db.blog.remove({title:"My Blog Post"}); | ||
|
17 changes: 17 additions & 0 deletions
17
sql/mongodb/MDBAuthedGuideSrc/ch02/02--myshell/defineConnectTo.js
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,17 @@ | ||
// 自定义连接函数脚本 | ||
var connectTo=function(port,dbname)// | ||
{ | ||
if(!port)// | ||
{ | ||
port=27017;//默认端口 | ||
} | ||
|
||
if(!dbname) // | ||
{ | ||
dbname="test";//默认连接的数据库 | ||
} | ||
|
||
// db 指向目标数据库 | ||
db=connect("localhost:"+post+"/"+dbname); | ||
return db; | ||
} |
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,51 @@ | ||
// 创建 mongorc.js 执行常用脚本 | ||
var compliment=["attractive","intelligent","like Batman"]; | ||
var index=Math.floor(Math.random()*3); | ||
|
||
print("Hello,you are looking paricularly "+compliment[index]+" today"); | ||
|
||
/*** | ||
*禁止某些危险函数 | ||
***/ | ||
// var no=function()// | ||
// { | ||
// print("Not on my watch"); | ||
// } | ||
// | ||
// //禁止删除数据库 | ||
// db.dropDatabase=DB.prototype.dropDatabase=no; | ||
// | ||
// //禁止删除集合 | ||
// DBCollection.prototype.drop=no; | ||
// | ||
// //禁止删除索引 | ||
// DBCollection.prototype.dropIndex=no; | ||
|
||
// 定制 shell 提示 —— 显示当前时间 | ||
// prompt=function()// | ||
// { | ||
// return (new Date())+"> "; | ||
// } | ||
|
||
// 定制 shell 提示 —— 显示当前使用的数据库 | ||
prompt=function()// | ||
{ | ||
if (typeof db=="undefined") // | ||
{ | ||
return "(nodb)> "; | ||
} | ||
|
||
// 检查最后的数据库操作 | ||
try// | ||
{ | ||
db.runCommand({getLastError:1}); | ||
}catch(e)// | ||
{ | ||
print(e); | ||
} | ||
|
||
return db+">"; | ||
} | ||
|
||
|
||
EDITOR="D:/Sublime Text 3/sublime_text"; |
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,52 @@ | ||
/*** | ||
*定义 shell 功能 | ||
***/ | ||
// 连接到指定服务器的指定数据库 | ||
mongo 127.0.0.1:27017/test | ||
|
||
db; | ||
|
||
// 启动时不连接任何数据库 | ||
mongo --nodb | ||
|
||
// 启动后转链接其他数据库 | ||
conn=new Mongo("127.0.0.1:27017"); | ||
db=conn.getDB("blog"); | ||
|
||
// 查看帮助 | ||
help | ||
|
||
// 查看数据库级别帮助 | ||
db.help(); | ||
|
||
// 查看集合级别帮助 | ||
db.blog.help(); | ||
|
||
//查看函数的用法 | ||
db.blog.update; | ||
|
||
// 加载脚本 defineConnectTo.js | ||
typeof connectTo; | ||
|
||
load('defineConnectTo.js'); | ||
|
||
typeof connectTo; | ||
|
||
// 查看当前工作目录 | ||
run("pwd"); | ||
|
||
// 启动时禁止加载 .mongorc.js | ||
mongo --norc | ||
|
||
|
||
// 调用编辑器编辑复杂变量 | ||
var wap=db.blog.findOne(); | ||
|
||
edit wap; | ||
|
||
/*** | ||
*访问特殊集合 | ||
***/ | ||
db.version;// 仅仅访问了内部的方法 | ||
|
||
db.getCollection("version"); //获取到集合 |
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,3 @@ | ||
tip="我是测试脚本"; | ||
|
||
print(tip); |
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 @@ | ||
### 第2章 MongoDB基础知识 |
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,32 @@ | ||
/*** | ||
*插入测试 | ||
***/ | ||
/*** | ||
* 简单插入 | ||
***/ | ||
db.foo.insert({"bar":"baz"}); | ||
|
||
db.foo.findOne(); | ||
|
||
/*** | ||
* 批量插入 | ||
***/ | ||
db.foo.insert([ | ||
{"_id":0}, | ||
{"_id":1}, | ||
{"_id":2} | ||
]); | ||
|
||
db.foo.find(); | ||
|
||
// 插入错误时候,前面会插入成功,后面会全部不插入 | ||
db.foo.insert([ | ||
{"_id":6}, | ||
{"_id":7}, | ||
{"_id":2}, | ||
{"_id":8} | ||
]); | ||
|
||
db.foo.find(); | ||
|
||
|
Oops, something went wrong.