2016-03-24 8 views
0

私は開発中ですSpring + Spring Data Mongo例です。この例では、Region is NULLという文書を取得したいと考えています。このため、私はmongoからNULLドキュメントを取得するために、SpringデータMongo Nullクエリを作成しますか?

List<Customer> findByRegionNull(); 

データベースクエリすぐdb.customers.find({ "リージョン": "NULL"})資本NULLなくヌルを示すリポジトリ方法を開発しました。 query execute結果が表示されません。 NULLを取得するためにリポジトリクエリを書く方法は?

db.customers.find({ "Region" : "NULL" }); 
    { 
     "_id" : ObjectId("51ba0970ae4ad8cc43bb95e3"), 
     "CustomerID" : "ALFKI", 
     "CompanyName" : "Alfreds Futterkiste", 
     "ContactName" : "Maria Anders", 
     "ContactTitle" : "Sales Representative", 
     "Address" : "Obere Str. 57", 
     "City" : "Berlin", 
     "Region" : "NULL", 
     "PostalCode" : 12209, 
     "Country" : "Germany", 
     "Phone" : "030-0074321", 
     "Fax" : "030-0076545" 
    } 
    { 
    "_id" : ObjectId("51ba0970ae4ad8cc43bb95e4"), 
    "CustomerID" : "ANATR", 
    "CompanyName" : "Ana Trujillo Emparedados y helados", 
    "ContactName" : "Ana Trujillo", 
    "ContactTitle" : "Owner", 
    "Address" : "Avda. de la Constitución 2222", 
    "City" : "México D.F.", 
    "Region" : "NULL", 
    "PostalCode" : 5021, 
    "Country" : "Mexico", 
    "Phone" : "(5) 555-4729", 
    "Fax" : "(5) 555-3745" 
} 

私は開発コード: CustomerRepository.java

public interface CustomerRepository extends CrudRepository<Customer, String>{ 
     List<Customer> findByRegionNull(); 
    } 

私のテストケースDoesnotは、結果を出しますか?

@Test 
    public void testRegionNull(){ 
     List<Customer> customers =cService.findByRegionNull(); 
     LOGGER.debug("SIZE : "+customers.size()); 
    } 

Customer.java

@Document(collection="customers") 
public class Customer { 
    @Id 
    private ObjectId id; 

    @Field("CustomerID") 
    private String customerId; 

    @Field("CompanyName") 
    private String companyName; 

    @Field("ContactName") 
    private String contactName; 

    @Field("ContactTitle") 
    private String contactTitle; 

    @Field("Address") 
    private String address; 

    @Field("City") 
    private String city; 

    @Field("Region") 
    private String region; 

    @Field("PostalCode") 
    private String postalCode; 

    @Field("Country") 
    private String country; 

    @Field("Phone") 
    private String phone; 

    @Field("Fax") 
    private String fax; 
    // setters and getters 
} 

答えて

関連する問題