Couchbase lite 2.0

can we save multiple data’s in same document ? ,

I tried it, but i got only updating the same value in single document, i want to store a person full conversation in specific document_id but it has updating only.

is it possible to store many documents in specific document not updating ?

Can you please elaborate with an example as to what you want to achieve. A document is a JSON object so you have the flexibility to store any logical collection of key-value pairs. I would recommend that you read this document on Couchbase documents

I don’t know what language or platform you are using . But if you were on swift, you’d do something like this to update an existing document . You can translate this to other languages easily

// get existing document with Id
let doc1b = db.document(withID: "doc1")

// Get mutable version of document . By default you get an immutable type
 let updatedDoc1b = doc1b!.toMutable()

// Set value for a new or existing key
 updatedDoc1b.setValue("Daniel Tiger", forKey: "name")

// Save the updated document
 let savedDoc1b = try saveDocument(updatedDoc1b)

Hi priya, thanks for your immediate reply,

I do in Android, I want to store many json data in single document with given specific I’d, like single person chat, kindly refer me some guides

That seems quite typical of how you would store data in your documents. The code snippet above should have given you an idea. You can fetch the current value for specified key and update that value. Check out the feature/2.0 branch of our Todo sample app for Android.

Thanks priya, I will check it out and I let you know got cleared or not

Hi priya,

I reffered this document, they have store every data in different document_id, but i want to store all data in specific document_id, is it possible to do ?

You can store as much data as you want in a single document — it’s JSON. Use multiple properties, use arrays, etc.

Storing all your data in one document would be a terrible idea, though. It removes all the advantages of having a database; you might as well just store the data in a JSON file:

  • All your data would be loaded into memory at once.
  • When you changed anything, all the data would get written back to disk
  • It becomes much harder to use query to find things in the data, and you can’t use indexes to optimize queries.
  • Replication will transfer all the data back and forth over the network whenever anything changes.

Thank you Jens for your immediate reply