0
両方のコレクションからマージ情報が必要なので、別のコレクションのデータを使用して1つのコレクションから情報を取得しようとしています。mongoDB 2.6の集計内の別のコレクションのデータを使用することは可能ですか
これは可能ですか?残念ながら
var Mclient = require('mongodb').MongoClient
var ObjectId = require('mongodb').ObjectID
//Connection URL
var url = 'url de conexao'
Mclient.connect(url, function (err, db){
console.log('Connect correctly to server')
var notes = db.collection('notes')
var cid = ObjectId("1")
notes.aggregate([
{ $match: {companyId:cid} },
{ $sort: {createdAt: -1}},
{ $unwind: "$users"},
{ $unwind: "$users.tags"},
{ $group: {
_id: '$_id' ,
Type: {$addToSet: '$type'},
ComanyId: {$addToSet: '$companyId'},
ProjectId: {$addToSet: '$projectId'},
Priority: {$addToSet: '$Priority'},
UsersData: {$push: {userId:"$users.userId", userTag: "$users.tags"}},
CreateDate: {$addToSet: '$createdAt'},
CompletedDate: {$addToSet: '$completedAt'},
DeletedDate: {$addToSet: '$deletedAt'},
total: {$sum: 1}
}
}]).each(function(err, doc, db){
if (doc){
var notes = db.collection('notes')
// Find para buscar outros dados usando dados do aggregate realizado acima
var dataNotes = notes.findOne({ _id: doc.ProjectId[0]})
}else{
return null
}
if (err) throw err
})
db.close()
})
助けてくれてありがとう=) – Kallan