6/15/2013

Mongo Advanced Search

In my test databasse, 
collection: testPatientInfo
document: testName (姓名), testID (身份證字號), testAge (年齡), testAddress (地址)
embedded document (內嵌文檔) of testAddress are: testNo (門牌號碼), testStreet (路名), testCity (城市), testCountry (國家), zip code (郵遞區號)

We are going to search the patient who lives in Taipei City, then we can use
db.Collection.find( { "Document.embedded document" : Value} );
In Mongo shell, the we can type
db.testPatientInfo.find( { "testAddress.testCity" : "Taipei"});



交集/ A且B

找學生為四年級且有40學分的紀錄
the student who is in 4th grade and has 40 points
由結果發現找出一筆符合的紀錄


找出特定搜尋條件的紀錄

找出學生姓名(student)為Hsu的學生的紀錄
DBObject query = new QueryBuilder().put("grade").is(4).get();


Not equals 

找出學生姓名不為Hsu的紀錄
DBObject query = new QueryBuilder().put("student").notEquals("Hsu").get();


$in/ in(inList)方法

db.CollectionName.find( {Document Name: [value1, value2, ...]})
找school表中學分數(point)為8, 13, 40紀錄
db.school.find( {point: [8, 13, 40]} );




$nin/ notIn(inList)

在Mongo shell中用 $nin,列出不包含這些資料的紀錄

在Java中可用notIn(inList)

skip方法




No comments:

Post a Comment