艺术家系列由艺术家的细节和艺术收藏品组成,包括特定艺术家的艺术细节。我想合并他们两个。我是mongodb的新手,在SQL中我知道如何执行操作,但是使用mongo很难找到它
艺术家系列
{
"_id" : ObjectId("571113f39542ab860bce85d7"),
"name" : "ajay",
"email" : "ajay@gmail.com",
"password" : "d6124b9d34be470dd0387dff9170c825cf8934ed",
"country" : "in",
"address" : "mysore",
"date_of_birth" : {
"year" : "1992:05:03"
},
"type" : "artist"
}
艺术收藏
{
"_id" : ObjectId("57161d2307e2432a49082903"),
"type" : null,
"originalname" : null,
"user_id" : "571113f39542ab860bce85d7",
"fullPath" : "/code/wd/artifu/backend/uploads/568eec81d2051abe2996f7139d46d143.png",
"created" : ISODate("2016-04-19T11:57:23.731Z"),
"data" : {
"title" : "image",
"description" : "description",
"tags" : "forest"
}
}
答案 0 :(得分:1)
function new(req, res, next) {
db.arts.findOne({
_id: mongoskin.helper.toObjectID(req.params._id)
}, function(err, art) {
if (err) return next(err);
if (!art) {
return res.status(404).send({
status: '404 file not found'
});
}
db.users.findOne({
_id: mongoskin.helper.toObjectID(art.user_id)
}, function(err, user) {
if (err) return next(err);
if (!user) {
return res.status(404).send({
status: '404 User not found'
});
}
return res.send({
user,art
});
})
});
}