Remove Element from Doubly Nested Array in MongoDB Document

Anvi Jain
Updated on 30-Jul-2019 22:30:25

2K+ Views

To remove an element from a doubly-nested array in MongoDB document, you can use $pull operator.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.removeElementFromDoublyNestedArrayDemo.insertOne(    ... {       ... "_id" : "1",       ... "UserName" : "Larry",       ... "UserDetails" : [          ... {             ... "UserCountryName" : "US",             ... "UserLocation" : [                ... { ... Read More

Avoid Duplicate Entries in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:25

1K+ Views

To avoid duplicate entries in MongoDB, you can use createIndex(). The syntax is as follows −db.yourCollectionName.createIndex({"yourFieldName":1}, {unique:true});Let us implement the above syntax. The query to avoid duplicate entries in MongoDB is a follows −> db.avoidDuplicateEntriesDemo.createIndex({"UserName":1}, {unique:true}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Now insert some records in the above collection. The query to insert record is as follows −> db.avoidDuplicateEntriesDemo.insertOne({"UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90e1824afe5c1d2279d697") }Here is the error whenever you try to insert the same record once again −> db.avoidDuplicateEntriesDemo.insertOne({"UserName":"John"}); 2019-03-19T18:03:08.465+0530 E QUERY [js] ... Read More

Add Elements to AbstractList Class in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

415 Views

To add elements to AbstractList class, the add() method is provided by the AbstractList class. The elemnt gets appended at the end of the list.The syntax is as follows:public boolean add(E ele)Here, the parameter ele is an element to be appended to this listTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to add elements to AbstractlList class in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       myList.add(100);       ... Read More

Hide Status Bar in iOS App Using Swift

Samual Sam
Updated on 30-Jul-2019 22:30:25

3K+ Views

Sometimes in our application, we need to hide the status bar, navigation bar, and other things and only show the content we want to display. In this article, we’ll see how to hide the status bar in our application. To hide status bar in our iOS application using swift language we need to go through very basic steps.We can hide the status bar in two general ways. Both of these methods involve a common step.Common StepGo to Your info.plist file.Add a key called “View controller-based status bar appearance” and set its value to NO.This was a common step we’ll use ... Read More

Remove All Documents Except One in MongoDB

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

788 Views

To remove all documents from a collection except a single document in MongoDB, use remove() based on some condition. Let us create a collection with documents. Following is the query>db.removeAllDocumentsExceptOneDemo.insertOne({"StudentName":"Larry", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9c9de42d66697741252478") } >db.removeAllDocumentsExceptOneDemo.insertOne({"StudentName":"Mike", "StudentAge":21, "StudentCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9c9dea2d66697741252479") } >db.removeAllDocumentsExceptOneDemo.insertOne({"StudentName":"Chris", "StudentAge":24, "StudentCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9c9def2d6669774125247a") }Following is the query to display all documents from a collection with the help of find() method> db.removeAllDocumentsExceptOneDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9c9de42d66697741252478"),    "StudentName" : "Larry",    "StudentAge" : ... Read More

P-Persistent CSMA Protocol

Fendadis John
Updated on 30-Jul-2019 22:30:25

6K+ Views

P-persistent CSMA is an approach of Carrier Sense Multiple Access (CMSA) protocol that combines the advantages of 1-persistent CMSA and non-persistent CMSA. Using CMSA protocols, more than one users or nodes send and receive data through a shared medium that may be a single cable or optical fiber connecting multiple nodes, or a portion of the wireless spectrum.In p-persistent CSMA, when a transmitting station has a frame to send and it senses a busy channel, it waits for the end of the transmission, and then transmits with a probability p. Since, it sends with a probability p, the name p ... Read More

Operations on Struct Variables in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

Here we will see what type of operations can be performed on struct variables. Here basically one operation can be performed for struct. The operation is assignment operation. Some other operations like equality check or other are not available for stack.Example#include typedef struct { //define a structure for complex objects    int real, imag; }complex; void displayComplex(complex c){    printf("(%d + %di)", c.real, c.imag); } main() {    complex c1 = {5, 2};    complex c2 = {8, 6};    printf("Complex numbers are:");    displayComplex(c1);    displayComplex(c2); }OutputComplex numbers are: (5 + 2i) (8 + 6i)This works fine as ... Read More

Store JSON Object Singleton with Global Context in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

336 Views

Before getting into example, we should know what singleton design pattern is. A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency and creating a central point of access for an application to access its data store.This example demonstrate about How to store JSON Object Singleton with Global Context in androidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the ... Read More

Find Objects Between Two Dates in MongoDB

Nancy Den
Updated on 30-Jul-2019 22:30:25

3K+ Views

Use operator $gte and $lt to find objects between two dates in MongoDB. To understand these operators, let us create a collection.Creating a collection here:>db.order.insert({"OrderId":1, "OrderAddrees":"US", "OrderDateTime":ISODate("2019-02-19")}; WriteResult({ "nInserted" : 1 }) >db.order.insert({"OrderId":2, "OrderAddrees":"UK", "OrderDateTime":ISODate("2019-02-26")}; WriteResult({ "nInserted" : 1 })Display all documents from the collection with the help of find() method. The query is as follows:> db.order.find().pretty();The following is the output:{    "_id" : ObjectId("5c6c072068174aae23f5ef57"),    "OrderId" : 1,    "OrderAddrees" : "US",    "OrderDateTime" : ISODate("2019-02-19T00:00:00Z") } {    "_id" : ObjectId("5c6c073568174aae23f5ef58"),    "OrderId" : 2,    "OrderAddrees" : "UK",    "OrderDateTime" : ISODate("2019-02-26T00:00:00Z") }Here is the query ... Read More

Using Include Directive Tag in JSP: Working Example

Samual Sam
Updated on 30-Jul-2019 22:30:25

358 Views

The include directive is used to include a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page.The general usage form of this directive is as follows −The filename in the include directive is actually a relative URL. If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP.You can write the XML equivalent of the above syntax as follows ... Read More

Advertisements