Creating additional document through iOS App


I am creating new document from iOS app using CB Lite. It is adding a document and also appending 2 more values which i don’t know why it is adding more?
Please see screenshot below. There is a square box shows in this screenshot with some values, those are getting added automatically.

Here is my iOS code:

import UIKit
import CouchbaseLiteSwift

class ViewController: UIViewController {

override func viewDidLoad() {
    // Do any additional setup after loading the view.
    setupCouchbase ()
func setupCouchbase () {
    // Get the database (and create it if it doesn’t exist).
    let database: Database
    do {
        database = try Database(name: "db")
    } catch {
        fatalError("Error opening database")
    // Create a new document (i.e. a record) in the database.
    let mutableDoc = MutableDocument()
        .setFloat(2.0, forKey: "version")
        .setString("SDK", forKey: "type")
    // Save it to the database.
    do {
        try database.saveDocument(mutableDoc)
    } catch {
        fatalError("Error saving document")
    // Update a document.
    if let mutableDoc = database.document(withID: {
        mutableDoc.setString("Swift", forKey: "language")
        do {
            try database.saveDocument(mutableDoc)
            let document = database.document(withID:!
            // Log the document ID (generated by the database)
            // and properties
            print("Document ID :: \(")
            print("Learning \(document.string(forKey: "language")!)")
        } catch {
            fatalError("Error updating document")
    // Create a query to fetch documents of type SDK.
    let query = QueryBuilder
    // Run the query.
    do {
        let result = try query.execute()
        print("Number of rows :: \(result.allResults().count)")
    } catch {
        fatalError("Error running the query")
    // Create replicators to push and pull changes to and from the cloud.
    let targetEndpoint = URLEndpoint(url: URL(string: "ws://")!)
    let replConfig = ReplicatorConfiguration(database: database, target: targetEndpoint)
    replConfig.replicatorType = .pushAndPull
    // Add authentication.
    replConfig.authenticator = BasicAuthenticator(username: "username", password: "xyz")
    // Create replicator.
    let replicator = Replicator(config: replConfig)
    // Listen to replicator change events.
    replicator.addChangeListener { (change) in
    if let error = change.status.error as NSError? {
        print("Error code :: \(error.code)")
    // Start replication.


Can you please advise me how to fix this - not creating dummy documents?

There are number of internal documents to manage the replication, which are all prefixed with “_sync” , You can ignore those documents, and shouldn’t be modified directly.

When i create a document through iOS app, these internal documents will be added by defualt? Is it possible to avoid getting it?

There is no on/off option to avoid generating “_sync” documents, the “_sync” documents are in use for sync to happen between Couchbase servers and Sync Gateway services.

In the future, we are going to add to the documentation for when these “_sync” docs are created and where they are used, please stay in tune for that.

You do not have to be concerned about them. They are metadata used internally by the System. You will never see them in the results of CBL queries. For direct N1QL queries, you will have to filter them - refer to this post

1 Like