這些僅僅是Spring Mongo數據靜止API中可用的休息端點。
{[/{people}],methods=[OPTIONS],produces=[application/hal+json || application/json]}
{[/{people}],methods=[HEAD],produces=[application/hal+json || application/json]}
{[/{people}],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}],methods=[GET],produces=[application/x-spring-data-compact+json || text/uri-list]
{[/{people}],methods=[POST],produces=[application/hal+json || application/json]}
{[/{people}/{id}],methods=[OPTIONS],produces=[application/hal+json || application/json]}
{[/{people}/{id}],methods=[HEAD],produces=[application/hal+json || application/json]}
{[/{people}/{id}],methods=[GET],produces=[application/hal+json || application/json]}
{{/{people}/{id}],methods=[PUT],produces=[application/hal+json || application/json]}
{[/{people}/{id}],methods=[PATCH],produces=[application/hal+json || application/json]}
{[/{people}/{id}],methods=[DELETE],produces=[application/hal+json || application/json]}
{[/ || ],methods=[OPTIONS],produces=[application/hal+json || application/json]}
{[/ || ],methods=[HEAD],produces=[application/hal+json || application/json]}
{[/ || ],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}/{id}/{property}],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}/{id}/{property}/{propertyId}],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}/{id}/{property}],methods=[DELETE],produces=[application/hal+json || application/json]}
{[/{people}/{id}/{property}],methods=[GET],produces=[application/x-spring-data-compact+json || text/uri-list]}
{[/{people}/{id}/{property}],methods=[PATCH || PUT || POST],consumes=[application/json || application/x-spring-data-compact+json || text/uri-list],produces=[application/hal+json || application/json]}
{[/{people}/{id}/{property}/{propertyId}],methods=[DELETE],produces=[application/hal+json || application/json]}
{[/{people}/search],methods=[HEAD],produces=[application/hal+json || application/json]}
{[/{people}/search],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}/search],methods=[OPTIONS],produces=[application/hal+json || application/json]}
{[/{people}/search/{search}],methods=[GET],produces=[application/hal+json || application/json]}
{[/{people}/search/{search}],methods=[GET],produces=[application/x-spring-data-compact+json]}
{[/{people}/search/{search}],methods=[OPTIONS],produces=[application/hal+json || application/json]}
{[/{people}/search/{search}],methods=[HEAD],produces=[application/hal+json || application/json]}
如果我們知道那個特定文檔的_id,我們可以得到一個人文檔。
我們只能使用搜索API獲取_embedded
json對象。例如,
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends MongoRepository<Person, String> {
List<Person> findAllByIdIsNotNull();
}
由於_id
不會在MongoDB中爲空,我們可以得到所有的文件,如果我們打這個端點http://localhost:8080/people/search/findAllByIdIsNotNull
。答覆如下。
{
"_embedded": {
"people": [{
"firstName": "N1",
"lastName": "N2",
"_links": {
"self": {
"href": "http://localhost:8080/people/59d54d2bb13148a7e93953c8"
},
"person": {
"href": "http://localhost:8080/people/59d54d2bb13148a7e93953c8"
}
}
}
}
只得到個人文件的最好方法是通過使用一些JSON解析API,如jq
在shell腳本或GSON /傑克遜在Java等
希望這有助於。