Nishtha Thakur has Published 443 Articles

Is there a way to limit the number of records in a certain MongoDB collection?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

134 Views

Yes, you can use capped parameter along with max size. Following is the syntax −db.createCollection("yourCollectionName", {capped:true, size:yourSizeInBytes, max:howManyRecordsYouWant})Let us first create a collection with capped:true −> db.createCollection("limitTheNumberOfRecordsDemo", {capped:true, size:200024, max:3}) { "ok" : 1 }We will now create a collection with documents −> db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"James Brown"}); {    "acknowledged" : true, ... Read More

Print numbers in sequence using thread synchronization

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

863 Views

Here we will see how to print numbers in a correct sequence using different threads. Here we will create n number of threads, then synchronize them. The idea is, the first thread will print 1, then second thread will print 2 and so on. When one thread is trying to ... Read More

How to keep two “columns” in MongoDB unique?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

1K+ Views

Use unique and set it to TRUE. Let us implement the same by creating index and setting two columns to unique −>db.keepTwoColumnsUniqueDemo.createIndex({"StudentFirstName":1, "StudentLastName":1}, {unique:true}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Now you can insert documents in the above collection ... Read More

Find a strict document that contains only a specific field with a fixed length?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

130 Views

You can use $where operator for this. Let us first create a collection with documents −>db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bcdb50a6c6dd317adb8") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bdbb50a6c6dd317adb9") } >db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ... Read More

Program for Christmas Tree in C

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

1K+ Views

Here we will see one interesting problem. In this problem, we will see how to print Christmas tree randomly. So the tree will be flickering like Christmas tree lights.To print a Christmas tree, we will print pyramids of various sizes just one beneath another. For the decorative leaves a random ... Read More

Project specific array field in a MongoDB collection?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

262 Views

Let us first create a collection with documents −> db.projectionAnElementDemo.insertOne( ...    { ...       "CustomerId":100, ...       "CustomerDetails": [ ...          { ...             "CustomerName": "Chris", ...             "CustomerCountryName": "US" ...   ... Read More

abs(), labs(), llabs() functions in C/C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

284 Views

In the cstdlib library of C++, there are different functions for getting the absolute value except from abs. The abs are used basically for int type input in C, and int, long, long long in C++. The others are used for long, and long long type data etc. Let us ... Read More

How to highlight a row in a table with Java Swing?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

1K+ Views

To highlight a row in a table, you can use the addRowSelectionInterval() method. At first create a table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);Add some columns −tableModel.addColumn("Language/ Technology"); tableModel.addColumn("Text Tutorial"); tableModel.addColumn("Video Tutorial"); tableModel.addColumn("Views");Now, add rows to the table −tableModel.addRow(new Object[] { "NodeJS", "No", "Yes", "2350"}); tableModel.addRow(new ... Read More

Efficient way to remove all entries from MongoDB?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

269 Views

If you will try to use the method drop(), then it will delete all information about the collection. Indexing is fast. However, if you will use the method remove(), then it removes all records but keeps the collection and indexes.Let us check with the help of example.Using drop()Let us first ... Read More

What is difference between GCC and G++ Compilers?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

904 Views

We use gcc and g++ compilers in different times. Here we will see what are the differences between gcc and g++.The gcc is GNU C compiler, and g++ is GNU C++ compiler. The main differences are like below −gcc can compile *.c or *.cpp files as C and C++ respectivelyg++ ... Read More

Advertisements