How to data insert?

sync gateway to couchbase server data insert question

sync_gateway version 3.1
couchbase server version 7.2

bucket name: sync_test
scope name : test
collection name : sync

  • test config : sgwsyncuser.json
{
"bootstrap": {
    "server": "couchbases://192.168.10.137",
    "username": "sync_gateway",
    "password": "password",
    "server_tls_skip_verify": true,
    "use_tls_server": true
  },
  "api":{
    "admin_interface": ":4985"
  },
  "logging": {
    "console": {
      "enabled": true,
      "log_level": "info",
      "log_keys": ["*"]
    }
  }
}
  • create test db
curl  --location --request PUT 'http://127.0.0.1:4985/syncdb/' \
      --header "Authorization: Basic $DIGEST" \
      --header 'Content-Type: application/json' \
      --data '{
          "bucket": "sync_test",
		  "scopes": {
          "test": {
              "collections": {
                  "sync": {
                    "sync": "function(doc){channel(\"collection name\");}",
                    "import_filter": "function(doc) { if (doc.type != 'mobile') { return false; } return true; }"
                    }
              }
          }
          },
          "num_index_replicas": 0 
          }'
  • data insert curl1
curl  --location --request PUT 'http://localhost:4985/sync_gateway.test.data/hotel_88802' \
      --header "Authorization: Basic $DIGEST" \
      --header 'Content-Type: application/json' \
      --data '{
          "_id": "hotel_88802",
          "id": "88802",
          "type": "hotel",
          "name": "Verify-Install Topic",
          "address": "The Shambles",
          "city": "Manchester",
          "country": "United Kingdom"
      }'
  • error message1
HTTP: c:#041 db:sync_gateway col:data PUT /sync_gateway.test.data/<ud>hotel_88802</ud> (as ADMIN)
HTTP: c:#041 db:sync_gateway col:data #041:     --> 403   (126.7 ms)
  • data insert curl 2
curl  --location --request PUT 'http://localhost:4985/syncdb/hotel_88802' \
      --header "Authorization: Basic $DIGEST" \
      --header 'Content-Type: application/json' \
      --data '{
          "_id": "hotel_88802",
          "id": "88802",
          "type": "hotel",
          "name": "Verify-Install Topic",
          "address": "The Shambles",
          "city": "Manchester",
          "country": "United Kingdom"
      }'
  • error message2
Auth: c:#043 db:syncdb #043: User <ud>sync_gateway</ud> was successfully authorized as an admin
HTTP: c:#043 db:syncdb PUT /syncdb/<ud>hotel_88802</ud> (as <ud>sync_gateway</ud> as ADMIN)
HTTP: c:#043 db:syncdb #043:     --> 404 keyspace syncdb._default._default not found  (2.6 ms)

Error 1 is referencing sync_gateway database name - which doesn’t match the one you created.

Error 2 is because your database has test scope and sync collection, but you’re using an API endpoint without declaring the scope and collection (keyspace) you want to write the document to.

Change your request to keyspace /syncdb.test.sync/

  1. Error 1 is referencing database name - which doesn’t match the one you created.sync_gateway - Should the database name be the same as ‘sync_gateway’?, If it should be the same, is it the sync_gateway database name? Is it a couchbase server?

Example 1 Is the create db phrase correct?

  • data insert curl1 a typing error

curl --location --request PUT ‘http://localhost:4985/sync_test.test.sync/hotel_88802
–header “Authorization: Basic $DIGEST”
–header ‘Content-Type: application/json’
–data '{
“_id”: “hotel_88802”,
“id”: “88802”,
“type”: “hotel”,
“name”: “Verify-Install Topic”,
“address”: “The Shambles”,
“city”: “Manchester”,
“country”: “United Kingdom”

Same as create test db
sync_gateway.test.data → sync_test.test.sync

No? You have two “Create/update document” requests you’re referring to as error 1 and error 2

Your create database is before those.

  • create test db
curl  --location --request PUT 'http://127.0.0.1:4985/syncdb/' \

This is fine ^ creating a database called syncdb with scope test and collection sync.


The next request is creating/updating a document called hotel_88802 inside database sync_gateway scope test collection data.

  • data insert curl1
curl  --location --request PUT 'http://localhost:4985/sync_gateway.test.data/hotel_88802' \

And the final one is creating/updating document hotel_88802 in database syncdb with the default scope and collection (which doesn’t exist in your create syncdb request)

  • data insert curl 2
curl  --location --request PUT 'http://localhost:4985/syncdb/hotel_88802' \