Wednesday, July 31, 2019

MongoDB Interview Questions

1) What do you understand by NoSQL databases? Is MongoDB a NoSQL database? explain.

At the present time, the internet is loaded with big data, big users, big complexity etc. and also becoming more complex day by day. NoSQL is answer of all these problems, It is not a traditional database management system, not even a relational database management system (RDBMS). NoSQL stands for "Not Only SQL". NoSQL is a type of database that can handle and sort all type of unstructured, messy and complicated data. It is just a new way to think about the database.
Yes. MongoDB is a NoSQL database.

2) Which are the different languages supported by MongoDB?

MonggoDB provides official driver support for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang.

You can use MongoDB with any of the above languages. There are some other community supported drivers too but the above mentioned ones are officially provided by MongoDB.

3) What are the different types of NoSQL databases? Give some example.

NoSQL database can be classified as 4 basic types:
  1. Key value store NoSQL database
  2. Document store NoSQL database
  3. Column store NoSQL database
  4. Graph base NoSQL databse
There are many NoSQL databases. MongoDB, Cassandra, CouchBD, Hypertable, Redis, Riak, Neo4j, HBASE, Couchbase, MemcacheDB, Voldemort, RevenDB etc. are the examples of NoSQL databases.

4) Is MongoDB better than other SQL databases? If yes then how?

MongoDB is better than other SQL databases because it allows a highly flexible and scalable document structure.
For example:
  • One data document in MongoDB can have five columns and the other one in the same collection can have ten columns.
  • MongoDB database are faster than SQL databases due to efficient indexing and storage techniques.

5) What type of DBMS is MongoDB?

MongoDB is a document oriented DBMS

6) What is the difference between MongoDB and MySQL?

Although MongoDB and MySQL both are free and open source databases, there is a lot of difference between them in the term of data representation, relationship, transaction, querying data, schema design and definition, performance speed, normalization and many more. To compare MySQL with MongoDB is like a comparison between Relational and Non-relational databases.

7) Why MongoDB is known as best NoSQL database?

MongoDb is the best NoSQL database because, it is:
Document Oriented
Rich Query language
High Performance
Highly Available
Easily Scalable

8) Does MongoDB support primary-key, foreign-key relationship?

No. By Default, MongoDB doesn't support primary key-foreign key relationship.

9) Can you achieve primary key - foreign key relationships in MongoDB?

We can achieve primary key-foreign key relationship by embedding one document inside another. For example: An address document can be embedded inside customer document.

10) Does MongoDB need a lot of RAM?

No. There is no need a lot of RAM to run MongoDB. It can be run even on a small amount of RAM because it dynamically allocates and de-allocates RAM according to the requirement of the processes.

11) Explain the structure of ObjectID in MongoDB.

ObjectID is a 12-byte BSON type. These are:
  • 4 bytes value representing seconds
  • 3 byte machine identifier
  • 2 byte process id
  • 3 byte counter

12) Is it true that MongoDB uses BSON to represent document structure?

Yes.

13) What are Indexes in MongoDB?

In MondoDB, Indexes are used to execute query efficiently. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement. If an appropriate index exists for a query, MongoDB can use the index to limit the number of documents it must inspect.

14) By default, which index is created by MongoDB for every collection?

By default, the_id collection is created for every collection by MongoDB.

15) What is a Namespace in MongoDB?

Namespace is a concatenation of the database name and the collection name. Collection, in which MongoDB stores BSON objects.

16) Can journaling features be used to perform safe hot backups?

Yes.

17) Why does Profiler use in MongoDB?

MongoDB uses a database profiler to perform characteristics of each operation against the database. You can use a profiler to find queries and write operations

18) If you remove an object attribute, is it deleted from the database?

Yes, it be. Remove the attribute and then re-save() the object.

19) In which language MongoDB is written?

MongoDB is written and implemented in C++.

20) Does MongoDB need a lot space of Random Access Memory (RAM)?

No. MongoDB can be run on small free space of RAM.

21) What language you can use with MongoDB?

MongoDB client drivers supports all the popular programming languages so there is no issue of language, you can use any language that you want.

22) Does MongoDB database have tables for storing records?

No. Instead of tables, MongoDB uses "Collections" to store data.


23) Do the MongoDB databases have schema?

Yes. MongoDB databases have dynamic schema. There is no need to define the structure to create collections.

24) What is the method to configure the cache size in MongoDB?

MongoDB's cache is not configurable. Actually MongoDb uses all the free spaces on the system automatically by way of memory mapped files.

25) How to do Transaction/locking in MongoDB?

MongoDB doesn't use traditional locking or complex transaction with Rollback. MongoDB is designed to be light weighted, fast and predictable to its performance. It keeps transaction support simple to enhance performance.

26) Why 32 bit version of MongoDB are not preferred ?

Because MongoDB uses memory mapped files so when you run a 32-bit build of MongoDB, the total storage size of server is 2 GB. But when you run a 64-bit build of MongoDB, this provides virtually unlimited storage size. So 64-bit is preferred over 32-bit.

27) Is it possible to remove old files in the moveChunk directory?

Yes, These files can be deleted once the operations are done because these files are made as backups during normal shard balancing operation. This is a manual cleanup process and necessary to free up space.

28) What will have to do if a shard is down or slow and you do a query?

If a shard is down and you even do query then your query will be returned with an error unless you set a partial query option. But if a shard is slow them Mongos will wait for them till response.

29)Explain the covered query in MongoDB.

A query is called covered query if satisfies the following two conditions:
  • The fields used in the query are part of an index used in the query.
  • The fields returned in the results are in the same index.

30) What is the importance of covered query?

Covered query makes the execution of the query faster because indexes are stored in RAM or sequentially located on disk. It makes the execution of the query faster.
Covered query makes the fields are covered in the index itself, MongoDB can match the query condition as well as return the result fields using the same index without looking inside the documents.

31) What is sharding in MongoDB?

In MongoDB, Sharding is a procedure of storing data records across multiple machines. It is a MongoDB approach to meet the demands of data growth. It creates horizontal partition of data in a database or search engine. Each partition is referred as shard or database shard.

32) What is replica set in MongoDB?

A replica can be specified as a group of mongo instances that host the same data set. In a replica set, one node is primary, and another is secondary. All data is replicated from primary to secondary nodes.

33) What is primary and secondary replica set in MongoDB?

In MongoDB, primary nodes are the node that can accept write. These are also known as master nodes. The replication in MongoDB is single master so, only one node can accept write operations at a time.
Secondary nodes are known as slave nodes. These are read only nodes that replicate from the primary.

34) By default, which replica sets are used to write data?

By default, MongoDB writes data only to the primary replica set.

35) What is CRUD in MongoDB?

MongoDB supports following CRUD operations:
  • Create
  • Read
  • Update
  • Delete

36) In which format MongoDB represents document structure?

MongoDB uses BSON to represent document structures.

37) What will happen when you remove a document from database in MongoDB? Does MongoDB remove it from disk?

Yes. If you remove a document from database, MongoDB will remove it from disk too.

38) Why are MongoDB data files large in size?

MongoDB doesn't follow file system fragmentation and pre allocates data files to reserve space while setting up the server. That's why MongoDB data files are large in size.

39) What is a storage engine in MongoDB?

A storage engine is the part of a database that is used to manage how data is stored on disk.
For example: one storage engine might offer better performance for read-heavy workloads, and another might support a higher-throughput for write operations.

40) Which are the storage engines used by MongoDB?

MMAPv1 and WiredTiger are two storage engine used by MongoDB.

41) What is the usage of profiler in MongoDB?

A database profiler is used to collect data about MongoDB write operations, cursors, database commands on a running mongod instance. You can enable profiling on a per-database or per-instance basis.
The database profiler writes all the data it collects to the system. profile collection, which is a capped collection.

42) Is it possible to configure the cache size for MMAPv1 in MongoDB?

No. it is not possible to configure the cache size for MMAPv1 because MMAPv1 does not allow configuring the cache size.

43) How to configure the cache size for WiredTiger in MongoDB?

For the WiredTiger storage engine, you can specify the maximum size of the cache that WiredTiger will use for all data. This can be done using storage.wiredTiger.engineConfig.cacheSizeGB option.

44) How does MongoDB provide concurrency?

MongoDB uses reader-writer locks for concurrency. Reader-writer locks allow concurrent readers shared access to a resource, such as a database or collection, but give exclusive access to a single write operation.

45) What is the difference between MongoDB and Redis database?

Difference between MongoDB and Redis:
  • Redis is faster than MongoDB.
  • Redis has a key-value storage whereas MongoDB has a document type storage.
  • Redis is hard to code but MongoDB is easy.


46) What is the difference between MongoDB and CouchDB?

Difference between MongoDB and CouchDB:
  • MongoDB is faster than CouchDB while CouchDB is safer than MongoDB.
  • Triggers are not available in MongoDB while triggers are available in CouchDB.
  • MongoDB serializes JSON data to BSON while CouchDB doesn't store data in JSON format.


47) What is the difference between MongoDB and Cassandra?

Difference between MongoDB and Cassandra:
  • MongoDB is cross-platform document-oriented database system while Cassandra is high performance distributed database system.
  • MongoDB is written in C++ while Cassandra is written in Java.
  • MongoDB is easy to administer in the case of failure while Cassandra provides high availability with no single point of failure.


48) Is there any need to create database command in MongoDB?

You don't need to create a database manually in MongoDB because it creates automaically when you save the value into the defined collection at first time.

Cassandra Interview Questions

1) Explain Cassandra.

Cassandra is a popular NOSQL database management system used to handle large amount of data. It is free and open source distributed database that provides high availability without any failure.

2) In which language Cassandra is written?

Cassandra is written in Java. It is originally designed by Facebook consisting of flexible schemas. It is highly scalable for big data.


3) Who was the original author of Cassandra?

The original authors of Cassandra are Avinash Lakshman and Prashant Malik. It was initially developed at Facebook to power the Facebook inbox search feature.

4) Which query language is used in Cassandra database?

Cassandra introduced its own Cassandra Query Language (CQL). CQL is a simple interface for accessing Cassandra, as an alternative to the traditional Structured Query Language (SQL).

5) What are the benefits/advantages of Cassandra?

  • Cassandra delivers real-time performance simplifying the work of Developers, Administrators, Data Analysts and Software Engineers.
  • It provides extensible scalability and can be easily scaled up and scaled down as per the requirements.
  • Data can be replicated to several nodes for fault-tolerance.
  • Being a distributed management system, there is no single point of failure.
  • Every node in a cluster contains different data and able to serve any request.

6) Where Cassandra stores its data?

Cassandra stores its data in the data dictionary.

7) What was the design goal of Cassandra?

The main design goal of Cassandra was to handle big data workloads across multiple nodes without a single point of failure.

8) How many types of NoSQL databases? Give some examples.

There are mainly 4 types of NoSQL databases:
  • Document store types ( MongoDB and CouchDB)
  • Key-Value store types ( Redis and Volgemort)
  • Column store types ( Cassandra)
  • Graph store types ( Neo4j and Giraph)

9) Mention some important components of Cassandra data models?

These are some key components of Cassandra data model: -
  • Table( collection of columns)
  • Node
  • Cluster
  • Keyspace

10) What are the other components of Cassandra?

Some other components of Cassandra are:
  • Node
  • Data Center
  • Commit log
  • Mem-table
  • SSTable
  • Bloom Filter

11) What is keyspace in Cassandra?

In Cassandra, a keyspace is a namespace that determines data replication on nodes. A cluster contains of one keyspace per node.

12) What are the different composite keys in Cassandra?

In Cassandra, composite keys are used to define key or a column name with a concatenation of data of different type. There are two types of Composite key in Cassandra:
  • Row Key
  • Column Name

13) What is data replication in Cassandra?

Data replication is an electronic copying of data from a database in one computer or server to a database in another so that all users can share the same level of information. Cassandra stores replicas on multiple nodes to ensure reliability and fault tolerance. The replication strategy decides the nodes where replicas are placed.

14) What is node in Cassandra?

In Cassandra, node is a place where data is stored.

15) 15) What do you mean by data center in Cassandra?

Data center is a complete data of clusters.

16) What do you mean by commit log in Cassandra?

In Cassandra, commit log is a crash-recovery mechanism. Every write operation is written to the commit log.

17) 17) What do you mean by column family in Cassandra?

Column family is a table in RDMS that contains an ordered collection of rows.

18) What do you mean by consistency in Cassandra?

Consistency in Cassandra specifies how to synchronize and up to date a row of Cassandra data and its replicas.

19) How many types of tunable consistency are supported in Cassandra?

It supports two consistencies: Eventual Consistency and Strong Consistency.
The eventual consistency is used when no new updates are made on a given data item, all accesses return the last updated value eventually. Systems with eventual consistency are known to have achieved replica convergence.

Cassandra supports the following conditions for strong consistency:
R + W > N
Here
N: Number of replicas
W: Number of nodes that need to agree for a successful write
R: Number of nodes that need to agree for a successful read

20) What is tunable consistency in Cassandra?

Tunable Consistency is a phenomenal characteristic of Cassandra which makes it a popular choice. Consistency refers to the up-to-date and synchronized data rows on all their replicas. Cassandra's Tunable Consistency facilitates users to select the consistency level best suited for their use cases.

21) What is the syntax to create keyspace in Cassandra?

  1. CREATE KEYSPACE <identifier> WITH <properties>  

22) What is a column family in Cassandra?

In Cassandra, a collection of rows is referred as "column family".

23) How does Cassandra perform write function?

Cassandra performs the write function by applying two commits:
  • First commit is applied on disk and then second commit to an in-memory structure known as memtable.
  • When the both commits are applied successfully, the write is achieved.
  • Writes are written in the table structure as SSTable (sorted string table).

24) What is memtable?

Memtable is in-memory/write-back cache space containing content in key and column format. In memtable, data is sorted by key, and each ColumnFamily has a distinct memtable that retrieves column data via key. It stores the writes until it is full, and then flushed out.

25) What is SSTable?

SSTable is a short form of 'Sorted String Table'. It refers to an important data file in Cassandra and accepts regular written memtables. They are stored on disk and exist for each Cassandra table.

26) How the SSTable is different from other relational tables?

SStables do not allow any further addition and removal of data items once written. For each SSTable, Cassandra creates three separate files like partition index, partition summary and a bloom filter.

27) What are the management tools in Cassandra?

DataStaxOpsCenter: It is an internet-based management and monitoring solution for Cassandra cluster and DataStax. It is free to download and includes an additional Edition of OpsCenter.
SPM: SPM primarily administers Cassandra metrics and various OS and JVM metrics. It also monitors Hadoop, Spark, Solr, Storm, zookeeper and other Big Data platforms besides Cassandra.

28) Mention some important features of SPM in Cassandra?

The main features of SPM are:
  • Correlation of events and metrics
  • Distributed transaction tracing
  • Creating real-time graphs with zooming
  • Detection and heartbeat alerting

29) What is cluster in Cassandra?

In Cassandra, the cluster is an outermost container for keyspaces that arranges the nodes in a ring format and assigns data to them. These nodes have a replica which takes charge in case of data handling failure.

30) What is the role of ALTER KEYSPACE?

ALTER KEYSPACE is used to change the value of DURABLE_WRITES with its related properties.

31) What do you mean by Cassandra-Cqlsh?

Cqlsh is a Cassandra query language shell used to execute the commands of CQL (Cassandra query language).

32) What are the differences between a node, a cluster, and datacenter in Cassandra?

Node: A node is a single machine running Cassandra.
Cluster: A cluster is a collection of nodes that contains similar types of data together.

Datacenter: A datacenter is a useful component when serving customers in different geographical areas. Different nodes of a cluster can be grouped into different data centers.

33) What is the use of Cassandra CQL collection?

Cassandra CQL collection is used to collect the data and store it in a column where each collection represents the same type of data. CQL consist of three types of types:
  • SET: It is a collection of unordered list of unique elements.
  • List: It is a collection of elements arranged in an order and can contain duplicate values.
  • MAP: It is a collection of unique elements in a form of key-value pair.

34) What is the use of Bloom Filter in Cassandra?

On a request of a data, before doing any disk I/O Bloom filter checks whether the requested data exist in the row of SSTable.

35) How does Cassandra delete data?

In Cassandra, to delete a row, it is required to associate the value of column to Tombstone (where Tombstone is a special value).

36) What is SuperColumn in Cassandra?

In Cassandra, SuperColumn is a unique element containing similar collection of data. They are actually key-value pairs with values as columns.

37) What is the difference between Column and SuperColumn?

Difference between Column and SuperColumn:
  • The values in columns are string while the values in SuperColumn are Map of Columns with different data types.
  • Unlike Columns, Super Columns do not contain the third component of timestamp.

38) What is Hadoop, HBase, Hive and Cassandra? Specify similarities and differences among them.

Hadoop, HBase, Hive and Cassandra all are Apache products.
Apache Hadoop supports file storage, grid compute processing via Map reduce. Apache Hive is a SQL like interface on the top of Haddop. Apache HBase follows column family storage built like Big Table. Apache Cassandra also follows column family storage built like Big Table with Dynamo topology and consistency.

39) What is the usage of "void close()" method?

In Cassandra, the void close() method is used to close the current session instance.

40) Which command is used to start the cqlsh prompt?

The cqlsh command is used to start the cqlsh prompt.

41) What is the usage of "cqlsh-version" command?

The "cqlsh-version" command is used to provide the version of the cqlsh you are using.

42) Does Cassandra work on Windows?

Yes. Cassandra is compatible on Windows and works pretty well. Now its Linux and Window compatible version are available.

43) What is Kundera in Cassandra?

In Cassandra, Kundera is an object-relational mapping (ORM) implementation which is written using Java annotations.

44) What do you mean by Thrift in Cassandra?

Thrift is the name of RPC client which is used to communicate with the Cassandra Server.

45) What is Hector in Cassandra?

Hector was one of the early Cassandra clients. It is an open source project written in Java using the MIT license.

CouchDB Interview Questions

1) What is CouchDB?

CouchDB is documented database server accessible through a RESTful JSON API. It is distributed, robust, incremental replication with bi-direction. It is schema-free with flat address space.
CouchDB is an open source NoSQL database which focuses on ease of use. It was developed by Apache. It is fully compatible with the web. CouchDB uses JSON to store data, JavaScript as its query language to transform the documents, using MapReduce, and HTTP for an API.
CouchDB features are as follows:

  • CouchDB can be replicated across multiple server instances.
  • CouchDB has various libraries for the language of your choice.
  • It has fast indexing and retrieval
  • It has a REST-like interface for document insertion, updates, recovery, and deletion.
  • CouchDB supports JSON-based document format, i.e., easily translatable across different languages.
Latest release: Version 2.2.0 on Aug 8, 2018

2) In which language CouchDB is written?

CouchDB is written in Erlang. It is a concurrent, functional programming language mainly focuses on fault tolerance (Erlang programming language also used for build massively scalable soft real-time system with requirements on high availability).
Some of its parts are written in C language too. As we know that CouchDB supports view server and the views (form map or reduce) are written in JavaScript per default (but can also be written in Erlang). Therefore CouchDB requires the JavaScript engine SpiderMonkey (which is written in C language).

3) In which language CouchDB's early work was started?

CouchDB early work was started in C++. But later, it was replaced by Erlang OTP platform.
Erlang has proven as an excellent match for this project.

4) How CouchDB is different from other SQL databases?

CouchDB is not a relational database. Some people think that it is a replacement for a relational database, but it is completely different from SQL databases. It is fast, efficient and faults tolerant.
Couch databaseSQL Databases
In CouchDB, JSON-based document format are used to store data, JavaScript for MapReduce indexes, and regular HTTP of its API.
Couch database is a database which stores data in the JSON document. Query your index and documents with the help of web browser via HTTP. All the indexes are combining with each other and transform with the help of JavaScript.
It is open source and uses RDBMS to store data. It is very fast, Multi-user, Multi-thread, and robust SQL (structured query language) database server.
SQL database generally used for big data storage of a large project.
It is a NoSQL database and likes manual transmission.It is a SQL database and likes automatic transmission.
Implemented in Erlang programming languageImplemented in C, C++ programming languages.
Structure of NoSQL database:
CouchDB interview questions

5) Is CouchDB used in the Software industry?

CouchDB is very popular now a day, and many companies are using CouchDB.
These are the essential features of CouchDB:
  • CouchDB can be replicated across multiple server instances.
  • CouchDB has various libraries for the language of your choice.
  • It has fast indexing and retrieval
  • It has a REST-like interface for document insertion, updates, recovery, and deletion.
  • CouchDB supports JSON-based document format, i.e., easily translatable across different languages.
That's why the software companies use CouchDB.
Here we have a list of Top companies which uses CouchDB:
CompanyWebsiteRevenueCompany sizeCountry
GrubHub Inc.grubhub.com200M-1000M1000-5000United States
Hothead Games, Inc.hotheadgames.com10M-15M50-200Canada
Ultimate software group Inc.Ultimatesoftware.com200M-1000M1000-5000United States
SLALOM,LLCSlalom.com200M-1000M5000-10000United States
GenCorp technologiesCredera.com10M-50M200-500United States

6) What is the difference between CouchDB and MongoDB?

These are the following differences:
CriteriaCouchDBMongoDB
InterfaceREST/HTTPTCP/IP Custom Protocol
Object StorageRecord is stored in documents in the database.Record is stored in collections in the database.
ReplicationIt follows Master-Master replication.It follows Master-Slave replication.
Query MethodCouchDB follows Map/Reduce query method. (JavaScript+others)MongoDB follows Map/Reduce (JavaScript) creating collection + object-based query language.
Data ModelIt follows the document-oriented model and data is presented in JSON format.Document-Oriented (BSON)
ConcurrencyMVVC (Multi-version concurrency control).Update-in-place
PreferenceCouchDB favors availabilityMongoDB favors Consistency
Performance consistencyIn CouchDB, data is safer than MongoDBIn MongoDB, the database contains collections and collection contains documents.It is faster than CouchDB.
Written inIt is written in Erlang.It is written in C++.
MongoDB is faster than CouchDB, and scalability is also better of the MongoDB.
CouchDB runs on different operating system like Android, iOS platform but MongoDB doesn't support mobile OS. Mongo DB is better as compare to CouchDB for rapid growth when the structure is not clearly defined from the beginning.

7) What is the similarity between MongoDB and CouchDB?

The similarity between MongoDB and CouchDB are:
  • MongoDB and CouchDB both are the document-oriented databases.
  • MongoDB and CouchDB both are the best examples of an open-source NoSQL database. i.e., both are Schema-free.
  • MongoDB and CouchDB both support JavaScript, can be used in queries, support aggregation functions such as MapReduce and sent the database to execute it.
  • MongoDB and CouchDB both support common programming languages C, C#, Erlang, Java, JavaScript, Ruby, Python, Haskell, PHP, Perl, Smalltalk, etc.
These are some common functionality of CouchDB and MongoDB.

8) What are the main features of CouchDB?

  • JSON Documents: CouchDB stores data in JSON document.
  • RESTful Interface: CouchDB does all tasks like replication, data insertion, etc. via HTTP.
  • N-Master Replication: CouchDB facilitates you to make use of an unlimited amount of 'masters,' making for some very interesting replication topologies.
  • Built for Offline: CouchDB can replicate to devices (like Android phones) that can go offline and handle data sync for you when the device is back online.
  • Replication Filters: CouchDB facilitates you to filter precisely the data you wish to replicate to different nodes.
  • ACID semantics: The CouchDB file layout follows all the features of ACID properties. Once the data is entered into the disc, it will not be overwritten. Document updates (add, edit, delete) follow Atomicity, i.e., they will be saved completely or not saved at all. The database will not have any partially saved or edited documents. Almost all of these update are serialized, and any number of clients can read a document without waiting and without being interrupted.
  • Document storage: CouchDB is a NoSQL database which follows document storage. Documents are the primary unit of data where each field is uniquely named and contains values of various data types such as text, number, Boolean, lists, etc. Documents don't have a set limit to text size or element count.
  • Eventually consistency: CouchDB guarantees to provide availability and partition tolerance.
  • Authentication and Session Support: CouchDB facilitates you to keep authentication open via a session cookie like a web application.
  • Security: CouchDB also provides database-level security. The permissions per database are separated into readers and admin. Readers can both read and write to the database.
  • Validation: You can validate the inserted data into the database by combining with authentication to ensure the creator of the document is the one who is logged in.
  • Map/Reduce List and Show: The main reason behind the popularity of MongoDB and CouchDB is map/reduce system.

9) Why Does CouchDB not use Mnesia?

There are many reasons behind CouchDB not using Mnesia:
  • It provides a storage limitation of 2 gigs per file.
  • It requires validation and fixup cycle after a crash or power failure, so even if the size limitation is lifted, the fixup time on large files is prohibitive.
  • Mnesia has some useful features, but features of Mnesia aren't really useful for CouchDB.
  • Mnesia is not a general-purpose, large-scale database. It works best as a configuration type database.
  • Mnesia works best as a configuration type database. It is necessary for the normal operations. The type where the data is not central to the function of the application, but necessary for normal operation of it.
  • Things that need to update, configure and often reconfigure like a network router, HTTP proxies, etc. whose configuration data is rarely huge.

10) How would you use transactions with CouchDB?

CouchDB uses an "Optimistic concurrency" model. In this model, if you send a document version along with your update, CouchDB rejects the change if the current document version doesn't match to your sent update.
So, you have to re-frame many normal transaction based scenarios for CouchDB. It's helpful to approach problems from a higher level, rather than attempting to mold Couch to a SQL based world.
If you have a document describing the item, and it includes a field for "Quantity available", you can handle concurrency issues:
First of all recover document, note down property that sent by CouchDB along with database, after that, Decrement the quantity field, if it's greater than zero. After that, send the updated document back using the _rev property. Check, If the _rev matches the currently stored number, be done else if there is a conflict when _rev is not matched then recover the newest document version.
For example:
I would like to take a ("master product") document that contains all the data information like name, picture description, price, etc.
Here we have to create to a field (product-key and, Claimed-by) by adding a new document inventory-ticket, if you are spelling a model of a hammer and have 20 items to sell, you might have documents with keys like hammer-1, hammer-2 to represent each one individually.

Now, I would like to create a view that gives a list of available hammer

  1.  Map  
  2. Function (doc)  
  3. {  
  4. If(doc.type== 'inventory-ticket' && doc.claimed_by==null)  
  5. {  
  6. emit(doc.product_key, { 'inventory-ticket' :doc.id, '_rev' : doc._rev});  
  7. }  
  8. }  
This gives me list of available tickets with their product_key, I could grab a group of these when someone wants to buy hammer then iterate through the sending updates until I successfully claim one.
Reduce
  1.  Function (keys, values, combine)  
  2.   
  3. {  
  4. Return values.length();  
  5. }  
This gives me a list of total unclaimed inventory_ticket items.
This example represents that transaction with CouchDB is possible that it substantially reduces conflicting updates, and cut down on the needs to respond to a conflict with the new updates. In this model, you won't have multiple users attempting to change data in primary product entry. When you have multiple users for a single ticket, then you have to identify those users who want to retake it by your view, ignore those, and you move to the next ticket and try again.

11) As CouchDB is written in Erlang and Erlang is known as slow to adopt Unicode. So, if it creates a problem for CouchDB?

CouchDB uses Erlang binary internally. So, data come to CouchDB is always UTF-8 encoded. There is no problem occurred.

12) What is the usage of CouchDB?

CouchDB facilitates developers to write a client-side application which interacts directly to the Couch without the need of server-side middle layer. It reduces the time of development and handling replication. Its database is stored locally so the application can run almost no latency. The main objective of CouchDB is to run on the internet applications and the connected devices through which we access the internet.
  • CouchDB has an HTTP-based REST API, which makes communication with the database very easy.
  • CouchDB has the simple structure of HTTP resources and methods (GET, PUT, and DELETE) that are easy to understand and use.
  • In CouchDB, data is stored in the flexible document-based structure so, there is no need to worry about the structure of the data.
  • CouchDB facilitates users with powerful data mapping, which allows querying, combining, and filtering the information.
  • CouchDB provides easy-to-use replication, using which you can copy, share, and synchronize the data between databases and machines.

13) What do you know about couchdbKit?

The couchdbKit provides a framework for your Python application to access and manage Python applications. It offers features to easily access and manage CouchDB by a client, allow to manage databases, Couch database server, doc management, and view access.
Objects mostly reflect python object for service. Server and data objects could be used for example.
Steps to install couchdbkit:
  • Couchdbkit requires python 2.x superior to 2.6
  • To install Couchdbkit using pip you must make sure that you have a recent version on distribute installed.
  • $ curl -0 http://python-distribute.org/distribute_setup.py
  • $ curl sudo python distribute_setup.py
  • $ easy_install pip
To install or upgrade to a latest released version of couchdbkit
$ pip install couchdbkit

14) Can Views update documents or databases?

No. Views are always read-only for databases and their documents.
Views are used for the following purpose:
  • It filters the document from the database to find relevant data for a particular process.
  • Extracting data from documents and present it in a specific order.
  • Building indexes to find the document by any value or structure that resides in them and use these indexes to represent the relationship between documents.
  • Finally, with views, you can make all sorts of calculations on the data in your documents
For example:
If documents represent your company's financial transactions, a view can answer the question of what the spending was in the last week, month, or year.

15) What platforms are supported in CouchDB?

Most POSIX systems are supported like GNU/Linux and OS X. Window is not officially supported but it should work.

16) What is the use of sequences? How do you do sequences?

Sequences are often used to ensure unique identifiers for each row in a database table. Sequences are hard to realize with replication. CouchDB generates unique ids from its own, and you can specify your own as well, so you don't need a sequence here. If you use a sequence for something else, you might find a way to express in CouchDB in another way.

17) How can you do replication?

Replication: Replication synchronizes two copies of the same database; these databases live on the same server or can be live on two different servers. If you change one copy of the database, replication will send the details to another copy.
For replication, first you have to send request of HTTP to CouchDB with a source, and a target database and CouchDB will send the changes from source to target.
Let's see, how replication looks like:
  1. POST /_replicate with a post body of </li>    
  2. {"source":"$source_database"   
  3. ,   
  4. "target":"$target_database"}  
Here $source_database and $target_database can be the names of local database or full URIs of remote databases. Both databases need to be created before they can be replicated from or to.

18) Is it possible to communicate to CouchDB without going through HTTP/ API?

CouchDB's data model and internal API map the REST/HTTP model in a very simple way that any other API would inherit some features of HTTP. However, there is a plan to refractor CouchDB's internals to provide a documented Erlang API.

Get max value for identity column without a table scan

  You can use   IDENT_CURRENT   to look up the last identity value to be inserted, e.g. IDENT_CURRENT( 'MyTable' ) However, be caut...