Learn NoSQL

Get hands-on with sample code, example queries, tutorials, and more

  • Server
  • Mobile
Couchbase Server
Download Couchbase Server
  • Enterprise
  • Community
Compare
Couchbase Server 6.5.1 Enterprise
Couchbase Server 6.5.1 Community
Code Intro
Code Intro
                                                                                                Read
                                                                                              // Get (Sync)
  JsonDocument myAirline = bucket.get("airline_5209");

  // Get (Async)
  Observable<JsonDocument>  myAirline = bucket.async().get("airline_5209"); // async using RxJava Observables!
                                                                                                Write
                                                                                              // Insert (Sync)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  JsonDocument stored = bucket.upsert(JsonDocument.create("walter", passenger));

  // Insert (Async)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  Observable<JsonDocument> stored = bucket.async().upsert(JsonDocument.create("walter", passenger));

  // Upsert (Sync)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  JsonDocument stored = bucket.upsert(JsonDocument.create("walter", passenger));

  // Upsert (Async)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  Observable<JsonDocument> stored = bucket.upsert(JsonDocument.create("walter", passenger));

  // Replace (Sync)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  JsonDocument replaced = bucket.replace(JsonDocument.create("walter", passenger));

  // Replace (Async)
  JsonObject passenger = JsonObject.empty()
  .put("firstname", "Walter")
  .put("lastname", "White");
  Observable<JsonDocument> walter2 = bucket.async().replace(JsonDocument.create("walter", passenger));
                                                                                                Query
                                                                                              // Query (String)
  Observable<AsyncN1qlQueryResult> theAirline = bucket
         .query(N1qlQuery
         .simple("SELECT name FROM `travel-sample` AS Airline WHERE id = 5209"));

  // Query (fluent API)
  Observable<AsyncN1qlQueryResult> theAirline = bucket
         .async()
         .query(N1qlQuery.simple(
           select("name")
             .from("travel-sample")
             .as("Airline")
             .where(x("id")
             .eq(5209))));
																					
                                                                                                Read
                                                                                              // Get Document
  bucket.get("walter", function (err, resRead) {/* handle results */});
                                                                                                Write
                                                                                              // Insert
  var key = "walter";
  bucket.insert(key, {firstname: "Walter", lastname: "White"},function(err, res) {/* handle results */});

  // Upsert
  var key = "walter";
  bucket.upsert(key, {firstname: "Walter", lastname: "White"},function(err, res) {/* handle results */});

  // Replace
  var key = "walter";
  bucket.replace(key, {firstname: "Walter", lastname: "White"},function(err, res) {/* handle results */});
                                                                                                Query
                                                                                              // Query (String)
  var N1qlQuery = couchbase.N1qlQuery;
  var query = N1qlQuery.fromString("SELECT name FROM `travel-sample` AS Airline WHERE id = 5209");
  bucket.query(query,function(err,result){/* handle results */});
																					
                                                                                                Read
                                                                                              // Get
  $res = $myBucket->get(‘document_name’);
                                                                                                Write
                                                                                              // Insert
  $res = $myBucket->insert('document_name', array('some'=>'value'));

  // Upsert
  $res = $myBucket->upsert('document_name', array('some'=>'value'));

  // Replace
  $res = $myBucket->replace('document_name', array('some'=>'value'));
                                                                                                Query
                                                                                              // Query (String)
  $myBucket->enableN1ql(array('http://1.1.1.1:8093/','http://1.1.1.2:8093/'));
  $query = CouchbaseN1qlQuery::fromString('SELECT * FROM default');
																					
                                                                                                Read
                                                                                              ' Get (Sync)
  var result = bucket.GetDocument("airline_5209");
                                                                                                Write
                                                                                              ' Insert (Sync)

  var passenger = new Document() {
   Firstname = "Walter",
   Lastname = "White"
  };
  bucket.Insert(passenger);

' Upsert (Sync)

  var passenger = new Document() {
   Firstname = "Walter",
   Lastname = "White"
  };
  bucket.Upsert(passenger);

  ' Replace (Sync)

  var passenger = new Document() {
   Firstname = "Walter",
   Lastname = "White"
  };
  bucket.Replace(doc);
                                                                                                Query
                                                                                              ' Query (String)
  var query = new QueryRequest("SELECT name FROM `travel-sample` AS Airline WHERE id = 5209");

  ' Query (using LINQ)

   var airlinesQuerySyntax = (
     from fromAirport in ClusterHelper.GetBucket(CouchbaseConfigHelper.Instance.Bucket).Queryable<Airport>()
     where fromAirport.Airportname == @from
     select new { fromAirport = fromAirport.Faa, geo = fromAirport.Geo })
         .ToList() // need to execute the first part of the select before call to Union
         .Union<dynamic>(
             from toAirport in ClusterHelper.GetBucket(CouchbaseConfigHelper.Instance.Bucket).Queryable<Airport>()
             where toAirport.Airportname == to
             select new { toAirport = toAirport.Faa, geo = toAirport.Geo });
																					
                                                                                                Read
                                                                                              # Get
  rv = bucket.get('document_name')
                                                                                                Write
                                                                                              # Insert
  rv = bucket.insert('document_name', {'some': 'value'})

  # Upsert
  rv = bucket.upsert('document_name', {'some': 'value'})

  # Replace
  rv = bkt.replace('document_name', {'some':'newvalue'}
                                                                                                Query
                                                                                              # Query (Simple)
  for row in bkt.n1ql_query('SELECT * FROM default'):

  # Query (Placeholders)
  q = N1QLQuery('SELECT fname, lname, age FROM default WHERE age > $age', age=22)
  for row in bkt.n1ql_query(q):
     ...
																					
                                                                                                Read
                                                                                              // Get
  cas, err := myBucket.Get("document_name", &myValue)
                                                                                                Write
                                                                                              // Insert
  cas, err := myBucket.Insert("document_name", &myDoc, 0)

  // Upsert
  cas, err := myBucket.Upsert("document_name", &myDoc, 0)

  // Replace
  cas, err := myBucket.Replace("document_name", &testValue, 0, 0)
                                                                                                Query
                                                                                              // Query (String)
  myQuery := gocb.NewN1qlQuery("SELECT * FROM default")
  rows, err := myBucket.ExecuteN1qlQuery(myQuery)
																					
Download Couchbase

Download Couchbase Server

Code Intro

Code Intro

Download Couchbase Mobile
Download Couchbase Mobile
  • Enterprise
  • Community
Compare
Couchbase Lite 2.7.1 Enterprise
Couchbase Lite 2.7.1 Community
  • Enterprise
  • Community
Compare
Couchbase Sync Gateway 2.7.2 Enterprise

Couchbase Sync Gateway 2.7.2, released in March 2020, is the second maintenance release in the 2.7.x series and includes important bug fixes. 

Couchbase Sync Gateway 2.7.2 Community

Couchbase Sync Gateway 2.7.2, released in March 2020, is the second maintenance release in the 2.7.x series and includes important bug fixes. 

Code Intro
Code Intro
                                                                                              OPEN DATABASE
// Get the database (and create it if it doesn’t exist).
let database = try Database(name: "my-database")

ADD  DOCUMENT
let newTask = MutableDocument()
       .setString("John", forKey: "firstName")
try database.saveDocument(newTask)


READ AND UPDATE  DOCUMENT
 guard let document = database.document(withID: "xyz") else { return }
let mutableDocument = document.toMutable()
mutableDocument.setString("jonny", forKey: "firstName")
try database.saveDocument(mutableDocument)
     
DELETE DOCUMENT
 try database.deleteDocument(mutableDocument)

ENABLING SYNC
let url = URL(string: "ws://localhost:4984/db")!
var replConfig = ReplicatorConfiguration(withDatabase: database, targetURL: url)
replConfig.replicatorType = .pull
let replication = Replicator(withConfig: replConfig)
replication.start()

QUERY
let query = QueryBuilder
   .select(SelectResult.all())
   .from(DataSource.database(database))
 .where(Expression.property("firstName").equalTo(Expression.string("jonny")))
   .limit(10)
																					
                                                                                              OPEN DATABASE
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"my-database" error:&error];


ADD  DOCUMENT
CBLMutableDocument *newTask = [[CBLMutableDocument alloc] init];
[newTask setString:@"firstName" forKey:@"john"];
CBLDocument *saved = [database saveDocument:newTask error:&error];

READ/ UPDATE  DOCUMENT
CBLDocument *document = [database documentWithID:@"xyz"];
CBLMutableDocument *mutableDocument = [document toMutable];
[mutableDocument setString:@"jonny" forKey:@"firstName"];
[database saveDocument:mutableDocument error:&error];

DELETE  DOCUMENT
[database deleteDocument: doc error: &error];


ENABLING SYNC
NSURL *url = [NSURL URLWithString:@"ws://localhost:4984/db"];
CBLURLEndpoint *target = [[CBLURLEndpoint alloc] initWithURL: url];
CBLReplicatorConfiguration *config = [[CBLReplicatorConfiguration alloc] initWithDatabase:database target:target];
config.replicatorType = kCBLReplicatorTypePull;               
CBLReplicator *replicator = [[CBLReplicator alloc] initWithConfig:config];
[replicator start];


QUERY
CBLQuery *query = [CBLQueryBuilder select:@[[CBLQuerySelectResult all]]
                                    from:[CBLQueryDataSource database:database]
                      where:[[CBLQueryExpression property:@"firstName"]
equalTo:[CBLQueryExpression string:@"jonny"]]
   groupBy:nil having:nil orderBy:nil
   limit:[CBLQueryLimit limit:[CBLQueryExpression integer:10]]];
																					
                                                                                              OPEN DATABASE
// Get the database (and create it if it doesn’t exist).
DatabaseConfiguration config = new DatabaseConfiguration(/* Android Context*/ context);
Database database = new Database("my-database", config);


CREATE DOCUMENT
MutableDocument newTask = new MutableDocument();
newTask.setString("firstName", "john");

database.save(newTask);

READ/ UPDATE  DOCUMENT
Document document = database.getDocument("xyz");
MutableDocument mutableDocument = document.toMutable();
mutableDocument.setString("firstName", "jonny");
 database.save(mutableDocument);

DELETE DOCUMENT
database.delete ( document);


ENABLING SYNC
URI uri = new URI("ws://localhost:4984/db");
Endpoint endpoint = new URLEndpoint(uri);
ReplicatorConfiguration config = new ReplicatorConfiguration(database, endpoint);
config.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL);
Replicator replication = new Replicator(config);
replication.start();

QUERY
Query query = QueryBuilder
       .select(SelectResult.expression(Meta.id),
               SelectResult.property("name"),
               SelectResult.property("type"))
       .from(DataSource.database(database))
       .where(Expression.property("firstName").equalTo(Expression.string("jonny")))
       .orderBy(Ordering.expression(Meta.id));
																					
                                                                                              OPEN DATABASE
// Get the database (and create it if it doesn’t exist).
 var database = new Database("my-database");


CREATE DOCUMENT
var dict = new Dictionary {
   ["firstName"] = "john"
};

var newTask = new MutableDocument(dict);
database.Save(newTask);


READ/ UPDATE  DOCUMENT
var newTask = database.GetDocument(“docId”).toMutable();
// We can directly access properties from the document object:
newTask.SetString("firstName", "jonny");
database.Save(newTask);

DELETE DOCUMENT
database.Delete(newTask);

ENABLE SYNC
var url = new Uri("ws://localhost:4984/db");
var replConfig = new ReplicatorConfiguration(database, url);
replConfig.ReplicatorType = ReplicatorType.Pull;
var replication = new Replicator(replConfig);
replication.Start();

QUERY
using(var query = QueryBuilder.Select(SelectResult.Property("name"))
   .From(DataSource.Database(database))
   .Where(Expression.Property("firstName").EqualTo(Expression.String("jonny")))
   .Limit(10))
																					
Sample Projects
Sample Projects

Couchbase Todo Training App: Step by Step

1. Couchbase Travel Sample Training App: A step-by-step walkthrough of all the various features of Couchbase Mobile using a sample travel application. Available for Swift, Java (Android), and C# (UWP, Xamarin).

2. Todo Sample App: A started to-do task list app for iOS, Android, and Windows.

3. A Query Playground for iOS: Playground for testing the Couchbase Mobile Query and Full-Text Search (FTS) capabilities.

Download Couchbase Mobile

Download Couchbase Mobile

Code Intro

Code Intro

Sample Projects

Sample Projects

Disable Tracking Protection

In order to download our product, we need you to fill out a form. To do so tracking protection must be disabled. Learn How