1.查看數(shù)據(jù)庫
創(chuàng)新互聯(lián)建站擁有一支富有激情的企業(yè)網(wǎng)站制作團隊,在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕10年,專業(yè)且經(jīng)驗豐富。10年網(wǎng)站優(yōu)化營銷經(jīng)驗,我們已為數(shù)千家中小企業(yè)提供了成都做網(wǎng)站、網(wǎng)站制作解決方案,按需制作,設(shè)計滿意,售后服務無憂。所有客戶皆提供一年免費網(wǎng)站維護!
show dbs
2.使用數(shù)據(jù)庫
use test
3.查看數(shù)據(jù)庫中的集合
show collections
4.向address集合添加數(shù)據(jù),如果address不存在則會創(chuàng)建
db.address.insertMany([
{
"building": "22 A, Indiana Apt",
"pincode": 123456,
"city": "Los Angeles",
"state": "California"
},
{
"building": "23 A, Indiana Apt",
"pincode": 123457,
"city": "Los Angeles2",
"state": "California2"
},
])
5.查看address集合中的數(shù)據(jù)
db.address.find().pretty()
6.向users集合添加數(shù)據(jù),如果users不存在會創(chuàng)建
db.users.insertOne({
"name":"Tom Benzamin",
"contact": "987654321",
"address_ids":[
ObjectId("5bd27e95abb45c7371f36ed3"),
ObjectId("5bd27e95abb45c7371f36ed4")
]
})
7.查看users集合中的數(shù)據(jù)
db.users.find().pretty()
8.查看用戶的地址信息
var result = db.users.findOne({"name":"Tom Benzamin"},{"address_ids":1})
var addresses = db.address.find({"_id":{"$in":result["address_ids"]}})
addresses[0]
addresses[1]