Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 26 of 81

filter_list() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 500 Views

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 More

Find documents that contains specific field in MongoDB?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 211 Views

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 More

Is it possible to return a list of specific values from a MongoDB query?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 228 Views

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 More

MongoDB query to get last inserted document?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 14K+ Views

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 More

Write an equality in MongoDB without using $eq operator

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 139 Views

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 More

Finding highest value from sub-arrays in MongoDB documents?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 293 Views

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 More

How to find and modify a value in a nested array?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 262 Views

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 More

How do I find all documents with a field that is NaN in MongoDB?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 1K+ Views

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 More

Using find() to search for nested keys in MongoDB?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 862 Views

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 More

Query MongoDB for a datetime value less than NOW?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 759 Views

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
Showing 251–260 of 810 articles
« Prev 1 24 25 26 27 28 81 Next »
Advertisements