1.查看已有集合
show collections
2.向集合中添加数据
db.runoob.insert({
title:'test',
description:'this is description',
by:'suyanzhu',
url:'https://blog.51cto.com/suyanzhu',
tags:['php','java','mongodb'],
likes:100
})
3.查看集合中数据信息
db.runoob.find()
4.通过定义变量存储数据信息,再添加到runoob集合中
document=({
"title" : "demo",
"description" : "this is description",
"by" : "yansuzhu",
"url" : "https://blog.51cto.com/suyanzhu",
"tags" : [
"php",
"sql",
"java"
],
"likes" : "100"
})
db.runoob.insert(document)
//或
db.runoob.save(document)