0

Ich habe folgendes Dokument (@Document):Frühling Daten und mongoDB - Aggregation mit Java-Liste

@Id 
private String id; 
private String fileName; 
private String projectId; 
private List<DocumentFileVersion> documentFileVersions; 
private List<String> userIdBlackList; // here userIds are included 

und dies ist meine aktuelle Aggregation:

final String userId = "5589929b887dc1fdb501cdbb"; 
final Aggregation aggregate = newAggregation(match(Criteria.where("projectId").in(projectId)), 
     group("fileName").count().as("amountOfDocumentFiles")); 
    final AggregationResults<DocumentFileAmount> groupDocumentFiles = mongoTemplate.aggregate(aggregate, DocumentFile.class, 
     DocumentFileAmount.class); 
    final List<DocumentFileAmount> documentFileAmounts = groupDocumentFiles.getMappedResults(); 
    final int amountOfDocumentFiles = documentFileAmounts.size(); 

Jetzt verlängern ich die aggreagation in Auf diese Weise habe ich nur die DocumentFiles, wo userId (in diesem Fall "1234") nicht in userIdBlackList ist. Gibt es eine Möglichkeit, das zu tun, wie in Pseudo-Code:

final Aggregation aggregate = newAggregation(match(Criteria.where("projectId").in(projectId).and(userId).notInList("userIdBlackList")), 
    group("fileName").count().as("amountOfDocumentFiles")); 

Ich würde so etwas wie dieses braucht: ... .und (userId) .notInList ("userIdBlackList") ...

[EDIT] ich diese Abfrage versucht haben:

final Aggregation aggregate = newAggregation(
     match(Criteria.where("projectId").in(projectId).and(userId).and("‌​userIdBlackList").ne(userId)), 
     group("fileName").count().as("amountOfDocumentFiles")); 

Eine Datenbank-Eintrag wie folgt aussehen:

{ 
"_id" : ObjectId("587e7cabafdaff28743f3034"), 
"_class" : "com.smartinnotec.legalprojectmanagement.dao.domain.DocumentFile", 
"fileName" : "Hydrangeas.jpg", 
"projectId" : "587e7c95afdaff28743f302e", 
"userIdBlackList" : [ 
    "5589929b887dc1fdb501cdbb" 
    ] 
} 

aber .und (userId) .und ("userIdBlackList"). Ne (userId) hat keine Wirkung.

[EDIT 2]

Ich habe versucht, auch in der Mongo-Konsole zu simulieren. Ich habe alle documentfiles mit dem Befehl db.DocumentFile.find() aufgelistet recht().

db.DocumentFile.find().pretty() 
{ 
"_id" : ObjectId("587f0d61473c92b933a68efa"), 
"_class" : "com.smartinnotec.legalprojectmanagement.dao.domain.DocumentFile", 
"fileName" : "DocumentFile1", 
"ending" : "jpg", 
"projectId" : "587f0d61473c92b933a68ef9", 
"active" : true, 
"userIdBlackList" : [ 
    "587f0d61473c92b933a68ef8" 
]} 

und meine Frage wie folgt aussieht:

db.DocumentFile.aggregate({ "$match" : { "projectId" : { "$in" : [ "587f0d61473c92b933a68ef9"]} , "‌​userIdBlackList" : { "$ne" : "587f0d61473c92b933a68ef8"}}}).pretty(); 
{ 
"_id" : ObjectId("587f0d61473c92b933a68efa"), 
"_class" : "com.smartinnotec.legalprojectmanagement.dao.domain.DocumentFile", 
"fileName" : "DocumentFile1", 
"ending" : "jpg", 
"projectId" : "587f0d61473c92b933a68ef9", 
"active" : true, 
"userIdBlackList" : [ 
    "587f0d61473c92b933a68ef8" 
]} 

ich erwartet, dass ich tun wegen dieses Ausdrucks keine Dokumentdatei erhalten "userIdBlackList": {"$ ne": "587f0d61473c92b933a68ef8"} Weiß jemand, was ich falsch mache?

[EDIT3]

Ich habe diese beiden Dokumente und mit der aggegate:

final Aggregation aggregate = newAggregation(
      match(Criteria.where("projectId").in(projectId).and("‌​userIdBlackList").nin(userId)), 
      group("fileName").count().as("amountOfDocumentFiles")); 

ich den Betrag von 2, aber es sollte 1. Ich weiß nicht, was ich tue falsch?

db.DocumentFile.find().pretty() 
{ 
"_id" : ObjectId("587f2228e232342f74b166f9"), 
"_class" : "com.smartinnotec.legalprojectmanagement.dao.domain.DocumentFile", 
"fileName" : "DocumentFile1", 
"ending" : "jpg", 
"projectId" : "587f2228e232342f74b166f8", 
"active" : true, 
"userIdBlackList" : [ 
    "587f2228e232342f74b166f7" 
]} 
{ 
"_id" : ObjectId("587f2228e232342f74b166fa"), 
"_class" : "com.smartinnotec.legalprojectmanagement.dao.domain.DocumentFile", 
"fileName" : "DocumentFile2", 
"ending" : "jpg", 
"projectId" : "587f2228e232342f74b166f8", 
"active" : true, 
"userIdBlackList" : [ ] 
} 
+0

versucht mit Haben Sie versucht, '$ ne' als' newAggregation (match (Criteria.where ("projectId"). In (projectId) .und (userId). und ("userIdBlackList") .ne (userId)), ... '? – chridam

+0

sry, es funktioniert nicht – quma

+0

Ich denke' und (userId) .and ("userIdBlackList") .ne (userId)) 'sollte be 'und (" userIdBlackList "). ne (userId))' – Veeram

Antwort

0

Haben Sie .nin

final Aggregation aggregate = newAggregation(
       match(Criteria.where("projectId").in(projectId).and("‌​userIdBlackList").nin(userId)), 
       group("fileName").count().as("amountOfDocumentFiles"));