I want to help get mongodb one of several documents. I have the following data structure:
db.coll.insert([
{_id: "gomer", doc_type: "user", group: ["user", "author"] },
{_id: "dante", doc_type: "user", group: ["user"] },
{_id: 1, doc_type: "blogs", user: "gomer", article: "aaaa" },
{_id: 2, doc_type: "blogs", user: "vasya", article: "bbbb" }
])
I want to get as a result of a request of the Joint Document:
{ _id:"123",
blogs: {id:1, doc_type: "blogs", user: "gomer", article: "aaaa"},
user : {id:"gomer", doc_type: "user", group: ["user", "author"]}
}
But I can not write a valid request:
db.coll.aggregate([
{ $match: {$or:[{doc_type:"blogs"},{doc_type:"user"}]} },
{ $project: {
blogs: { id:$id, doc_type:"blogs", user:$user, article:$article },
user: { id:$id, doc_type:"user", group:$group }
}
}
])
How to make a request?