Professional Documents
Culture Documents
Document databases pair each key with a complex data structure known as a document. Documents can
contain many different key-value pairs, or key-array pairs, or even nested documents.
Graph stores are used to store information about networks of data, such as social connections. Graph
stores include Neo4J and Giraph.
Key-value stores are the simplest NoSQL databases. Every single item in the database is stored as an
attribute name (or 'key'), together with its value. Examples of key-value stores are Riak and Berkeley DB.
Some key-value stores, such as Redis, allow each value to have a type, such as 'integer', which adds
functionality.
Wide-column stores such as Cassandra and HBase are optimized for queries over large datasets, and
store columns of data together, instead of rows.
ACID: BASE:
• Atomicity • Basically Available (CP)
• Consistency • Soft-state
• Isolation • Eventually consistent (AP)
• Durability
db.createCollection(name, options)
In the command, name is name of collection to be created. Options is a document and is used to specify
configuration of collection.
Parameter Type Description
Options parameter is optional, so you need to specify only the name of the collection. Following is the list of options
you can use −
Field Type Description
db.mycol.find({"by":"tutorials point"}).pretty()
db.mycol.find(
{
$and: [ {key1: value1}, {key2:value2} ]
}).pretty()
• db.users.aggregate([
{ $lookup:
{
from: 'products',
localField: 'zipcode',
foreignField: 'zipcode',
as: 'orderdetails'
}
}
])
MongoDB Configuration
Step 1: Locate the folder where you have installed MongoDB. If you have followed the above steps then you can
find the folder at this location:
C:\Program Files\MongoDB
Here you need to create couple of folders that we need for MongoDB configuration.
1. Create two folders here, name them data and log.
2. Create another folder inside data and name it as db, that’s where all the data will be stored.
That’s it close the window.
Step 2: Open command prompt (right click and run as administrator). Navigate to the bin folder of MongoDB as
shown in the screenshot. The path to the bin folder may be different in your case based on where you have
installed the MongoDB.
Step 3: Configure the data & log folder and set MongoDB as service by typing this command. Note:This is a one
line command.
mongod --directoryperdb --dbpath "C:\Program Files\MongoDB\data\db"
--logpath "C:\Program Files\MongoDB\log\mongo.log" --logappend --rest --install
Step 4: Now you can start MongoDB as a service by typing this command:
net start MongoDB
You should see a message “MongoDB service was started successfully”.
That’s it everything is done. Now we should be working in the MongoDB shell and we can run that by typing this
command within the bin directory.
mongo
Administration:
Command => db.runCommand(<command>)
use products
db.runCommand( { revokeRolesFromUser: "accountUser01",
roles: [
{ role: "read", db: "stock" },
"readWrite"
],
writeConcern: { w: "majority" }
})
Optional. The authentication restrictions the server enforces upon the user.
authenticationRestrictions array Specifies a list of IP addresses and CIDR ranges from which the user is allowed
to connect to the server or from which the server can accept users.