Assignment Group 2B
Assignment Group 2B
Using MongoShell
1.
2.
3.
4.
5.
6. use spcoe;
7. switch to db spcoe;
Connect to database:
To connect database, you need to specify database name, if database
doesn't exist then mongodb creates it automatically.
Classes in mongo-java-driver.jar:
1.DB:(public abstract class DB extends
Object) Package: com.mongodb.DB
An abstract class that represents a logical database on a server
Constructor
s:
DB( Mongo mongo, String name)
Method Summary:
Modifier
and
Method
Descriptio
n
Type
void
addOption(int option)
DBCollectio
n
Set<
String>
getCollectionFromString
(String s)
Mongo
getMongo()
createCollection( String
DBCollection name,
DBObject options)
boolean
authenticate( String
username,
Authenticat
e
database user
char[] password)
void
dropDatabase()
Constructors :
DBCollection(DB base, String name)
Method Summary:
Modifier
Method
Descriptio
n
and Type
long
count()
void
createIndex( DBObject
keys)
calls
createIndex(com.mongodb.DB
Object,
com.mongodb.DBObject)
default index options
void
DBCursor
drop()
WriteResu
insert( DBObject... arr)
lt
WriteResu
remove( DBObject o)
lt
calls
with
remove(com.mongodb.DBObje
ct,
com.mongodb.WriteConc
ern)
with
Constructors :
MongoClient() : Creates an instance based on a (single) mongodb node
(localhost,
default port).
Constructors :
public BasicDBObject(int size): creates an empty object
public BasicDBObject(int size): creates an empty object
Constructors :
public DBCursor(DBCollection collection,DBObject q,
DBObject k, ReadPreference preference)): Initializes
a new database cursor
Method Summary:
Modifier and Method
Description
Type
public booleanhasNext()
available
public DBObject
next()
public void
RDBMS
MongoDB
Database
Database
Table
Collection
Tuple/Row
Document
column
Field
Table Join
Embedded Documents
Primary Key
RDBMS
public int
_id provided by
mongodb itself)
MongoDB
MongoDB Overview:
MongoDB is a cross-platform, document oriented database that
provides,
high
performance,
high
availability,
and
easy
scalability.
Below given example shows the document structure of a blog site which is
simply a comma separated key value pair.
{
_id:
ObjectId(7df78ad8902c)
title: 'MongoDB Overview',
['mongodb',
'database',