How to restrict duplicate entry in couchbase lite with flutter

I am inserting new record in database, then performing save Document,
after every refreshing of code in flutter , the document count is increasing. Actual there are only 2 records , it is creating multiple duplicate entries.

First off, I’m not sure how you’re calling Couchbase Lite from Dart, but we don’t support Dart, so there’s a limit to how much we can help.

after every refreshing of code in flutter , the document count is increasing

If your code inserts a new record every time it runs, then I would expect that a refresh would add a new document, since it restarts the app (right?) Could you describe what you’re expecting to happen?

If you want to delete the database every time the app starts (for development purposes), you’ll need to do that explicitly.

If you want to create the document if and only if it doesn’t already exist, you should give it an explicit ID when it’s created. If it already exists, the save will fail with a ‘conflict’ error.

Calling Couchbase lite with this package: Fluttercouch(

class AppModel extends Model with Fluttercouch {
String _databaseName;
Document docExample;
Query query;

AppModel() {

initPlatform async {
try {
print(“Inititaing couchbase database”);
_databaseName = await initDatabaseWithName(“Useerinfo”);
print(await getDocumentCount()); // This gives the count of document
MutableDocument newDoc = MutableDocument();
newDoc.setString(“name”, “abc”); // by this inserting the document in database
doc = await saveDocument(newDoc); // saving the document


By this code on every refresh it count is increasing in database.

Sure. That’s what I’d expect that code to do. You are reopening the same database on every launch, and creating a new document. So the number of documents increases by one.

Again, what did you expect to happen?

Thanks for the reply.
what did you expect to happen: want to retrieve couchbase lite data in flutter .