Java Login

About javalogin.com

Hello guys,
javalogin.com is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.


     << Previous


MongoDB Interview Questions


Q. Can we store Regular expression in MongoDB?
Ans. Yes, We can do.
For this there is data type i.e Regular expression.

Q. How to store array in MongoDB?
Ans.


db.mycollectiontest.insert(
{
"_id": ObjectId(7df78ad8902c),
"url": "http://www.example.com",
"tags": ["mongodb", "database", "NoSQL"],
})


Q. What is syntax to update the document in collection?
Ans. db.collectiontest.update(SELECTIOIN_CRITERIA, UPDATED_DATA)

Q. How to remove one document in collection?
Ans. db.collectiontest.remove({'title':'title'},1)

Q. How to remove document based on search criteria?
Ans. db.collectiontest.remove({'title':'title'})

Q. How to use limit with search?
Ans. db.collectiontest.find({},{"title":1,_id:0}).limit(2)

Q. How to sort the documents?
Ans. ->sort({"title":-1});
1: Ascending Order
-1: Descending Order

Q. What is Replication in MongoDB?
Ans. Replication is the process of synchronizing data across multiple servers.
Replication increases data availability with multiple copies of data on different database servers.

Q. How replication works in MongoDB?
Ans. click here Replication

Q. What is a Covered Query?
Ans. It is query in which all the fields in the query are part of an index and all the fields returned in the query are in the same index.

Q. What is capped collection in MongoDb? How capped collections are created in MongoDb?
Ans. Capped collection is a special kind of collection in MongoDb, what can have limit on collection storage. That means in this collection we can restrict the size of collection or we can put limit on size of collection, these special type of collection is named as Capped Collection.

Lets take a look at the syntax of creating capped collection:

db.createCollection(<Collection_Name>, {capped: Boolean, autoIndexId: Boolean, size: Number, max : Number})

db.createCollection(<Collection_Name>, {capped: Boolean, autoIndexId: Boolean, size: Number, max : Number})

The syntax is near about same as the syntax of creating collection. Lets understand the syntax first :

Collection_Name : Name of collection that needs to be created as capped collection.

capped : Capped is the Boolean flag, true if the collection needs to created as capped collection, by default the value is false.

autoIndexId : Boolean flag, used for autoindexing, if true indexes will be created automatically, false will say indexes will not be created automatically.

size : Size parameter says the max size of documents in bytes, it is mandatory field in case of capped collections.

max : max parameter says the max number of documents allowed in a collection. Size is given preference over size.

MongoDb provides a method isCappped() to check if the collection is capped or not. Below is the syntax for the same:

db.<Collection_Name>.isCapped()

db.<Collection_Name>.isCapped()


     << Previous