Tuesday, June 25, 2024
HomeGolangGetting error whereas studying information from azure cosmos db utilizing azcosmos NewQueryItemsPager...

Getting error whereas studying information from azure cosmos db utilizing azcosmos NewQueryItemsPager – Code Evaluation


I’m making an attempt to learn information from azure cosmos db desk utilizing azcosmos package deal. Within the earlier model it’s working tremendous which is v0.3.5. I’ve upgraded it to v0.3.6.
Now the queryPager.NextPage(context.Background()) is throwing “no Host in request URL”.

Can somebody inform what goes fallacious in my code?

Line 37 queryResponse, err := queryPager.NextPage(context.Background()) is throwing error.

package deal essential

import (


func GetUser() {
	endpoint := os.Getenv("Cosmos_DB_Endpoint")
	key := os.Getenv("Cosmos_DB_Key")

	cred, err := azcosmos.NewKeyCredential(key)
	if err != nil {
		log.Deadly("Didn't create a credential: ", err)

	// Create a CosmosDB consumer
	consumer, err := azcosmos.NewClientWithKey(endpoint, cred, nil)
	if err != nil {
		log.Deadly("Didn't create Azure Cosmos DB consumer: ", err)

	container, _ := consumer.NewContainer("DIM", "On-Behalf")
	pk := azcosmos.NewPartitionKeyNumber(1)

	queryPager := container.NewQueryItemsPager("SELECT c['On-Behalf'] FROM c", pk, nil)
	var end result []map[string]interface{}

	for queryPager.Extra() {
		queryResponse, err := queryPager.NextPage(context.Background())
		if err != nil {
			var responseErr *azcore.ResponseError
			errors.As(err, &responseErr)

		for _, merchandise := vary queryResponse.Objects {
			var itemResponseBody map[string]interface{}
			err = json.Unmarshal(merchandise, &itemResponseBody)
			end result = append(end result, itemResponseBody)
			if err != nil {
	fmt.Print(end result)

func essential() {



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments