Einige andere Verfahren fügt Dokumente in Mongo Sammlung und unten ist, die BeispieldatenMongoDB QueryByExample FindOne
{ "_id" : ObjectId("597b89c8da52380b04ee6948"), "_class" : "com.test.mongo", "clientId" : "CAQ123999", "isValid" : false, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6949"), "_class" : "com.test.mongo", "clientId" : "CAQ123999", "isValid" : false, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6950"), "_class" : "com.test.mongo", "clientId" : "CAQ123998", "isValid" : true, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6951"), "_class" : "com.test.mongo", "clientId" : "CAQ123997", "isValid" : true, "isParent" : false }
Ich versuche, ein Rekord für die clientId zu packen, mit QueryByExampleExecutor.
Hier ist mein Modell
package com.test.cfp.model;
public class TFSModel {
private String clientId;
private boolean isValid;
private boolean isParent;
...
}
Hier ist der Code, um das Beispiel zu erstellen:
TFSModel tfs = new TFSModel();
tfs.setClientId(CAQ123999);
tfs.setValid(false);
tfs.setParent(true);
ExampleMatcher matcher =ExampleMatcher.matching().withIgnoreNullValues().withIgnorePaths("_id","_class");
Example<TFSModel > example = Example.of(tfs,matcher);
TFSModel oneTfsRecord = tflsRepository.findOne(example);
Dies funktioniert nicht, unten ist die erzeugte Abfrage
findOne using query: { "isValid" : false , "isParent" : true , "clientId" : "CAQ123999" , "_class" : { "$in" : [ "com.test.cfp.model.TFSModel"]}} in db.collection: returns.tfs;
Offensichtlich hat die Klasse das andere Paket als das in der Mong o Sammlung. Wie kann ich Mongo sagen, eine Abfrage ohne _class zu erstellen. Ich habe versucht mit IgnoredPaths und es funktioniert nicht.
Dank @Christoph Strobl. Ich habe MongoTemplate verwendet. Ich bin mir nicht sicher, ob es ein gültiges Szenario ist oder nicht. Jedenfalls werde ich versuchen, dies in jira.spring.io zu protokollieren. – PKR