Ich habe dieses DokumentMehrere Filter in MongoDB Abfrage
{
"_id" : ObjectId("6afda532e9a0e3838537c71a"),
"VersionId" : 0,
"NodeId" : [
{
"NodeId" : 0,
"Host" : "127.0.0.1",
"DatabaseName" : "NodeId0",
"Collection" : [
{
"CollectionId" : 0,
"CollectionName" : "Codice0"
},
{
"CollectionId" : 1,
"CollectionName" : "Codice1"
}
]
},
{
"NodeId" : 1,
"Host" : "127.0.0.2",
"DatabaseName" : "NodeId1",
"Collection" : [
{
"CollectionId" : 1,
"CollectionName" : "Codice1"
}
]
}
]
}
und möchte für CollectionId
nur 1 eingereicht von nodeId
und 1 Feld extrahieren, ist es möglich?
Das zurückgegebene Dokument sollte diese Struktur hat:
{
VersionId: 0,
NodeId: {
NodeId: 0,
Collection: {
CollectionId: 0,
CollectionName: Codice0
}
}
}
ich diese Abfrage versuchte, ohne Erfolg:
let queryDatabasePath = collezioneDbPath.aggregate([
{ $match: { "VersionId" : versionId } },
{ $project: {
NodeId : { $filter: {
input: '$NodeId',
as: 'prova',
cond: {$and: [
{$eq: ['$$prova.NodeId' , nodeId ]},
{$filter: {
input:'$prova',
as: 'prova1',
cond: {$eq: ['$$prova1.Collection.CollectionId', collectionId]}
}}
]}
} },
//"NodeId.Collection.CollectionId" : 1,
_id: 0
} }
], function (err, res) {
console.log(res);
});
Vielen Dank für Ihre schnelle Antwort, Problem gelöst! : D –