******* This document is a daily learning record, which is convenient for later review, so it will not be explained in detail
1. Add objects to the data table and embed collection data
db.FanCenter.insert([
{
source:'mall',
createTime:new Date(),
usersTypes:[
{
userType:'1',
remark: '访问用户',
count:'2',
users:[{
phone:'4352345',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date(),
},
{
phone:'4325235',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date(),
}
]
},
{
userType:'2',
remark: '注册用户',
count:'1',
users:[{
phone:'53442',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date(),
},
{
phone:'23453245',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date(),
}
]
}
]
}
])
2. Add a new field to the specified object
db.getCollection("FanCenter").update({ source: "mall" },
{ $set: { "updateTime": new Date()} })
3. Add an object to the specified collection in the specified object
db.getCollection("FanCenter").update({ source: "website" },
{ $push: { usersTypes:
{
userType:'2',
remark: '访问用户',
count:'2',
users:[{
phone:'2345325',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date()
},
{
phone:'2342525',
sex:'男',
dateCreated: new Date(),
dateUpdated: new Date()
}
]
}
}
})
4. Delete the specified object
db.FanCenter.remove({'source':'mall'})
.
.
.
Afterword: After I found out that my white shoes were dirty, my partner would brush me clean, so I decided to buy only white shoes from now on.