Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Chandu yadav
Page 26 of 81
filter_list() function in PHP
The filter_list() function in PHP returns an array of all available filter names that can be used with PHP's filter functions like filter_var() and filter_input(). Syntax filter_list() Parameters This function does not accept any parameters. Return Value The function returns an indexed array containing the names of all available filters. If no filters are available, it returns an empty array. Example Here's how to use filter_list() to display all available filters − Practical Example with Filter IDs You can combine filter_list() with filter_id() to ...
Read MoreFind documents that contains specific field in MongoDB?
To find documents that contain a specific field in MongoDB, use the $exists operator. This operator checks whether a field exists in a document, regardless of its value. Syntax db.collection.find({ "fieldName": { $exists: true } }); Sample Data Let us create a collection with sample documents − db.findDocumentContainsSpecificFieldDemo.insertMany([ { "ProductPrices": { "Product1": 10, ...
Read MoreIs it possible to return a list of specific values from a MongoDB query?
Yes, you can return a list of specific values from a MongoDB query using the map() method or projection. The map() method transforms query results into an array of specific field values. Syntax db.collection.find().map(function(document){ return document.fieldName; }); Sample Data db.listOfSpecificValuesDemo.insertMany([ {"StudentName": "John"}, {"StudentName": "Chris"}, {"StudentName": "Robert"}, {"StudentName": "David"} ]); { "acknowledged": true, "insertedIds": { ...
Read MoreMongoDB query to get last inserted document?
To get the last inserted document in MongoDB, use sort() with _id in descending order along with limit(1). Since ObjectId contains a timestamp, sorting by _id in descending order retrieves the most recently inserted document. Syntax db.collection.find().sort({_id: -1}).limit(1); Sample Data Let us first create a collection with documents ? db.getLastInsertedDocument.insertMany([ {"Name": "John"}, {"Name": "Chris"}, {"Name": "Robert"} ]); { "acknowledged": true, "insertedIds": [ ...
Read MoreWrite an equality in MongoDB without using $eq operator
In MongoDB, you can write equality queries without using the $eq operator by using the implicit equality syntax. This involves directly specifying the field name and value in the query document. Syntax db.collection.find({"fieldName": "value"}); Sample Data Let us first create a collection with documents ? db.operatorDemo.insertMany([ {"StudentSubject": ["MongoDB", "MySQL", "Java"]}, {"StudentSubject": ["Java", "C", "C++"]} ]); { "acknowledged": true, "insertedIds": [ ObjectId("5cef94eaef71edecf6a1f6a2"), ...
Read MoreFinding highest value from sub-arrays in MongoDB documents?
To find the highest value from sub-arrays in MongoDB documents, use the aggregation framework with $unwind, $sort, and $limit operators to flatten arrays, sort by the target field, and return the top result. Syntax db.collection.aggregate([ { $unwind: "$arrayField" }, { $sort: { "arrayField.valueField": -1 } }, { $limit: 1 } ]); Sample Data db.findHighestValueDemo.insertMany([ { _id: 10001, "StudentDetails": [ ...
Read MoreHow to find and modify a value in a nested array?
To find and modify a value in a nested array, use the $elemMatch operator to locate the array element and the $ positional operator with $set to update the specific field value. Syntax db.collection.update( { arrayName: { $elemMatch: { field: "matchValue" } } }, { $set: { "arrayName.$.targetField": "newValue" } } ); Sample Data db.findAndModifyAValueInNestedArrayDemo.insertOne({ "CompanyName": "Amazon", "DeveloperDetails": [ { ...
Read MoreHow do I find all documents with a field that is NaN in MongoDB?
To find all documents with a field that is NaN in MongoDB, use the $eq operator or direct comparison with NaN value in your query. Syntax db.collection.find({ fieldName: NaN }); Or using the $eq operator: db.collection.find({ fieldName: { $eq: NaN } }); Create Sample Data First, let's create a collection with documents containing various numerical values including NaN ? db.nanDemo.insertMany([ { "Score": 0/0 }, // NaN { "Score": 10/5 }, ...
Read MoreUsing find() to search for nested keys in MongoDB?
To search for nested keys in MongoDB, use dot notation to specify the path to the nested field. This allows you to query documents based on values within embedded objects. Syntax db.collectionName.find({"outerField.innerField": "value"}); Sample Data Let us create a collection with nested documents ? db.searchForNestedKeysDemo.insertMany([ { "ClientName": "Larry", "ClientAge": 28, "ClientExtraDetails": { ...
Read MoreQuery MongoDB for a datetime value less than NOW?
To query MongoDB for datetime values less than the current time, use the $lte operator with new Date() which returns the current timestamp. Syntax db.collection.find({ "dateField": { $lte: new Date() } }); Sample Data db.dateTimeValueLessThanNowDemo.insertMany([ { "CustomerName": "Larry", "CustomerProductName": "Product-1", "ArrivalDate": new ISODate("2017-01-31") }, { ...
Read More