Created
May 21, 2020 01:50
-
-
Save RaviTella/e544ef7b266ba425abead7f05193f717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.demo; | |
import com.microsoft.azure.documentdb.*; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.stereotype.Service; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import java.util.List; | |
@SpringBootApplication | |
public class DemoApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
@RestController | |
public class MyController { | |
@Autowired | |
CosmosService cosmosService; | |
@GetMapping("/hello") | |
public String hello() throws Exception { | |
cosmosService.connectCosmos(); | |
return "OK"; | |
} | |
} | |
@Service | |
public class CosmosService { | |
public void connectCosmos() throws Exception { | |
DocumentClient client = new DocumentClient("https://somename-cosmosdb.documents.azure.com:443/", "somepassword", new ConnectionPolicy(), ConsistencyLevel.Session); | |
client.getDatabaseAccount(); | |
FeedOptions options = new FeedOptions(); | |
options.setEnableCrossPartitionQuery(true); | |
List<Document> result = client | |
.queryDocuments( | |
"dbs/" + "samples" + "/colls/" + "orders", | |
"SELECT * FROM c", | |
options) | |
.getQueryIterable() | |
.toList(); | |
result | |
.stream() | |
.forEach(System.out::println); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment