> 声明和打印
> var x = "hello world"
> print(x)
hello world
> function jspang(){
... return "jspang"
... }
> print(jspang())
jspang
简单的几个命令
1. 显示数据库
> show dbs
admin 0.000GB
local 0.000GB
2. 进入哪个库
> use admin
switched to db admin
3. 显示集合
> show collections
system.version
4. 查看当前库
> db
admin
>
第二节:
> db.user.insert({"name":"simoon"})
WriteResult({ "nInserted" : 1 })
//写入成功
> db.user.find()
{ "_id" : ObjectId("5b188d3f4b9d59cfbeca6fb2"), "name" : "simoon" }
//查找
> db.user.insert({"name":"lilei"})
WriteResult({ "nInserted" : 1 })
> db.user.insert({"name":"hanmeimei"})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5b188d3f4b9d59cfbeca6fb2"), "name" : "simoon" }
{ "_id" : ObjectId("5b188d724b9d59cfbeca6fb3"), "name" : "lilei" }
{ "_id" : ObjectId("5b188d774b9d59cfbeca6fb4"), "name" : "hanmeimei" }
//继续插入三个集合
> db.user.findOne()
{ "_id" : ObjectId("5b188d3f4b9d59cfbeca6fb2"), "name" : "simoon" }
//查找第一个对象
> db.user.update({"name":"simoon"}, {"name":"simoon","age":"18"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
//修改数据几个
> db.user.remove({"name":"simoon"})
WriteResult({ "nRemoved" : 1 })
//删除一个集合
> db.user.drop()
true
//删库跑路
> show dbs
admin 0.000GB
local 0.000GB
> use user
switched to db user
> db.user.insert({"name":"simoon"})
WriteResult({ "nInserted" : 1 })
> db.dropDatabase()
{ "dropped" : "user", "ok" : 1 }
//删库跑路2
第三节:
var name = "simoon";
var timeStamp = +new Date();
var jsonDatabase = {longinName: name, longinTime: timeStamp};
var db = connect('log');
//这里相当于use log
db.login.insert(jsonDatabase)
print('[demo]:logPringSuccess')
> show dbs
admin 0.000GB
local 0.000GB
log 0.000GB
> use log
switched to db log
> db
log
//log是数据库
> show collections
login
//login 是数据集合
> db.login.find()
{ "_id" : ObjectId("5b18960422947375c06db265"), "longinName" : "simoon", "longinTime" : 1528337924925 }
>