1.查看数据库
show dbs
2.使用数据库
use test
3.查看数据库中的集合
show collections
4.添加集合中添加数据(使用嵌入式方法,可以将用户地址嵌入到用户的文档中)
db.sites.insertOne({
"name": "Tom Hanks",
"contact": "987654321",
"dob": "01-01-1991",
"address":[
{
"building": "22 A, Indiana Apt",
"pincode": 123456,
"city": "Los Angeles",
"state": "California"
},
{
"building": "23 A, Indiana Apt",
"pincode": 123457,
"city": "Los Angelea",
"state": "Californiaf"
},
]
})
5.查看集合中的数据
db.sites.find().pretty()
6.查询用户的地址
db.sites.findOne({"name":"Tom Hanks"},{"address":1})