Saving Offline data into CB Lite 2.0


#1

issue : ( CB Lite 2.0 , Swift)

  1. Registration screen which has name, email and dob and want to save in couchbase lite.
  2. everytime user-filled form with these fields I want to store in local CB Lite DB
  3. After that i want to fetch all record store in the cb lite.

Issue is :

Created a document

stored name , emal and dob in swift dictionary and tried to save and it stores but everytime i fetch it shows only one , not other user information.

Kinldy help me on this.


#2

Can you show the code you’re using to store & fetch the documents?


#3

Thanks for reply , i solved the issue this way

https://stackoverflow.com/a/51812268/3400991 here is my post on stack.

let dict = [
“alert”: “push notification… (5)”,
“badge”: 1,
“sound”: “default”
] as [String : Any]

        var notificationArray = [Dictionary<String,Any>]()

        let notiDict = CouchDBHelper.fetchDocumentByDocId(documentID: Constants.notificationDocument)

        if let notiArray = notiDict["notification"] as? [Dictionary<String,Any>] {
            notificationArray = notiArray
        }
        notificationArray.append(dict)

        CCouchDBHelper.insertNotificationData(data: notificationArray, doc_id: Constants.notificationDocument)
        objNotifcationSource = notificationArray
        objNotificationTable.reloadData()



   public func insertNotificationData(data:Any?,doc_id:String)
    {
        //let sharedInstance = CouchbaseAdapter.sharedInstance
        let doc = MutableDocument(id: doc_id) 

        doc.setValue(data, forKey: "notification")

        do {
            try database.saveDocument(doc)
            //try sharedInstance.database.saveDocument(doc)
            print("Inserted Record :", data as! NSArray)
        } catch let error as NSError {
            print("Error in saving",error)
        }

        fetchDocumentByDocId(documentID: doc_id)
    }