MongoDB集合数据操作
时间:2018-10-24 17:07 来源:51cto.com 作者:51cto
1.查看已有集合
show collections
2.向集合中添加数据
db.runoob.insert({
title:'test',
description:'this is description',
by:'suyanzhu',
url:'http://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" : "http://blog.51cto.com/suyanzhu",
"tags" : [
"php",
"sql",
"java"
],
"likes" : "100"
})
db.runoob.insert(document)
//或
db.runoob.save(document)
(责任编辑:IT)
1.查看已有集合 show collections
2.向集合中添加数据 db.runoob.insert({ title:'test', description:'this is description', by:'suyanzhu', url:'http://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" : "http://blog.51cto.com/suyanzhu", "tags" : [ "php", "sql", "java" ], "likes" : "100" }) db.runoob.insert(document) //或 db.runoob.save(document)
(责任编辑:IT) |