您好,登錄后才能下訂單哦!
1.查看數(shù)據(jù)庫
show dbs
2.創(chuàng)建runoob數(shù)據(jù)庫
use runoob
3.查看runoob中集合
show collections
4.創(chuàng)建地址集合(address_home,address_office)
db.createCollection("address_home")
db.createCollection("address_office")
5.查看創(chuàng)建的集合
show collections
6.分別向家庭(address_home)地址集合和辦公(address_office)地址集合添加數(shù)據(jù)
db.address_home.insertOne({
'name':'home address',
'province':'jiangsu',
'city':'xuzhou'
})
查看address_home數(shù)據(jù)
db.address_home.find().pretty()
db.address_office.insertOne({
'name':'office address',
'province':'jiangsu',
'city':'nanjing'
})
查看address_office數(shù)據(jù)
db.address_office.find().pretty()
7.創(chuàng)建用戶集合(users)
db.createCollection("users")
8.查看創(chuàng)建集合
show collections
9.向users集合添加數(shù)據(jù)
db.users.insertOne({
"name":"suyanzhu",
"address":{
"$ref":"address_home",
"$id":ObjectId("5bd2b70fabb45c7371f36eda")
},
"age":18
})
查看集合中的數(shù)據(jù)
db.users.find().pretty()
10.查看用戶具體的地址信息
var user = db.users.findOne({"name":"suyanzhu"})
user
var dbRef = user.address
dbRef
var collName = dbRef.$ref
collName
var id = dbRef.$id
id
db[collName].findOne({"_id":id})
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。