MongoDB playground All In One
MongoDB playground All In One
MongoDB REPL
db={
"teacher": [
{
"_id": ObjectId("64fee9b54273ac2234441225"),
"teacherid": ObjectId("64f1d72a4331bc8fc4c5930f"),
"name": "xgqfrms"
}
],
"users": [
{
_id: ObjectId("64f1d72a4331bc8fc4c5930f"),
name: "eric"
}
]
}
aggregate
db.teacher.aggregate([
{
$match: {
"teacherid": ObjectId("64f1d72a4331bc8fc4c5930f")
}
},
{
$lookup: {
from: "users",
localField: "teacherid",
foreignField: "_id",
as: "student"
}
},
{
$unset: "name"
}
])
// ]).explain()
// ]).pretty()
// Unsupported method: only find(), aggregate(), update() and explain() are supported
demos
mongo
$ mongo
# replace the `YOUR_DATABASE_NAME` with your real database name.
> use YOUR_DATABASE_NAME
# update Teacher collection ✅
> db.Teacher.update(
{"teacherid" : "64f1d72a4331bc8fc4c5930f"},
{
$set: {"teacherid" : ObjectId("64f1d72a4331bc8fc4c5930f")}
});
> db.Teacher.aggregate([
{
$match: {
"teacherid": ObjectId("64f1d72a4331bc8fc4c5930f")
}
},
{
$lookup: {
from: "user",
localField: "teacherid",
foreignField: "_id",
as: "student"
}
},
{
$unset: "name"
}
]).pretty();
Node.js
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
MongoDB 跨表
查询
https://www.cnblogs.com/xgqfrms/p/17724984.html#5215297
refs
https://www.cnblogs.com/xgqfrms/p/17724984.html#5215324
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17736878.html
未经授权禁止转载,违者必究!