Samual Sam has Published 2492 Articles

How to find all objects created before specified Date in MongoDB?

Samual Sam

Samual Sam

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

499 Views

You can use $lt operator for this. Let us create a collection with documents −> db.beforeSpecifyDateDemo.insertOne({"UserLoginDate":new ISODate('2016-03-21')}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd91e4de8cc557214c0e0d") } > db.beforeSpecifyDateDemo.insertOne({"UserLoginDate":new ISODate('2016-05-11')}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd91ecde8cc557214c0e0e") } > db.beforeSpecifyDateDemo.insertOne({"UserLoginDate":new ISODate('2017-01-31')}); {    "acknowledged" : true,    "insertedId" ... Read More

How to select only numeric strings in MongoDB?

Samual Sam

Samual Sam

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

421 Views

Let us create a collection with documents −> db.selectOnlyNumericDemo.insertOne({"UserId":"User101"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdb711de8cc557214c0e16") } > db.selectOnlyNumericDemo.insertOne({"UserId":"102"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdb716de8cc557214c0e17") } > db.selectOnlyNumericDemo.insertOne({"UserId":"User103"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdb71dde8cc557214c0e18") } > db.selectOnlyNumericDemo.insertOne({"UserId":"104"}); {    "acknowledged" : true, ... Read More

MongoDB query to match each element in a documents array to a condition?

Samual Sam

Samual Sam

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

165 Views

You can use every() in MongoDB for this. Let us create a collection with documents −> db.arrayConditionDemo.insertOne({"Name":"John", "Marks":[40, 43, 45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdbd06de8cc557214c0e1a") } > db.arrayConditionDemo.insertOne({"Name":"Mike", "Marks":[45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdbd17de8cc557214c0e1b") } > db.arrayConditionDemo.insertOne({"Name":"Chris", "Marks":[43, 45, 59, 69, 78, ... Read More

Get output of MongoDB shell script?

Samual Sam

Samual Sam

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

700 Views

You can use printjson() or print() to get output of MongoDB shell script. Let us create an array of objects.Following is the query to create an array of objects.> var studentDetails=[{"StudentName":"John", "StudentAge":21},    {"StudentName":"Carol", "StudentAge":24}, {"StudentName":"David", "StudentAge":25}];Following is the query to get the output of Mongo shell script using printjson() ... Read More

Does Mongo shell treats numbers as float by default.? How can we work it around explicitly?

Samual Sam

Samual Sam

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

191 Views

Yes, Mongo shell treats numbers as float by default. To work it as int or any other type, you need to mention explicitly. You can use NumberInt() for this. The syntax is as follows −var anyVariableName= [NumberInt("yourValue1"), NumberInt("yourValue2"), .....N];Let us implement the above syntax in order to treat numbers as ... Read More

Get attribute list from MongoDB object?

Samual Sam

Samual Sam

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

923 Views

To get attribute list from MongoDB object, you can use for loop to extract key and value for document. Let us create a collection with documents −>db.getAttributeListDemo.insertOne({"StudentId":101, "StudentName":"John", "StudentAdmissi onDate":new ISODate('2019-01-12'), "StudentSUbjects":["MongoDB", "Java", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdfcc9ac184d684e3fa269") }Display all documents from a collection with ... Read More

Generate random numbers using C++11 random library

Samual Sam

Samual Sam

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

1K+ Views

In C++11, we can get the random library to generate random numbers. Here we have used random_device once to seed the random number generator object called mt. This random_device is slower than the mt19937, but we do not need to seed it. It requests for random data to the operating ... Read More

How does generic lambda work in C++14?

Samual Sam

Samual Sam

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

178 Views

In C++11, the lambda was introduced. Lambdas are basically a part of, that can be nested inside other function call statements. By combining lambda expressions with the auto keyword, they can be used later.In C++14, these lambda expressions are improved. Here we can get the generalized or generic lambda. For ... Read More

How to initialize a const field in constructor?

Samual Sam

Samual Sam

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

687 Views

Here we will see how to initialize the const type variable using constructor?To initialize the const value using constructor, we have to use the initialize list. This initializer list is used to initialize the data member of a class. The list of members, that will be initialized, will be present ... Read More

How to get memory usage under Linux in C++

Samual Sam

Samual Sam

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

2K+ Views

Here we will see how to get the memory usage statistics under Linux environment using C++.We can get all of the details from “/proc/self/stat” folder. Here we are taking the virtual memory status, and the resident set size.Example#include #include #include #include #include using namespace std; ... Read More

Advertisements