Skip to content

Instantly share code, notes, and snippets.

@RaviTella
Created May 21, 2020 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaviTella/e544ef7b266ba425abead7f05193f717 to your computer and use it in GitHub Desktop.
Save RaviTella/e544ef7b266ba425abead7f05193f717 to your computer and use it in GitHub Desktop.
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