Arjun Thakur

Arjun Thakur

749 Articles Published

Articles by Arjun Thakur

Page 28 of 75

filter_id() function in PHP

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 373 Views

The filter_id() function returns the filter ID of a provided filter name. This is useful when you need to work with filter IDs directly or verify that a filter exists. Syntax filter_id(filtername) Parameters filtername − The name of filter to get the ID from. Return Value The filter_id() function returns filter ID on success or FALSE, if the filter does not exist. Example Here's how to get filter IDs for all available filters ? int = 257 boolean = 258 float = ...

Read More

How to limit the amount of characters returned from a field in a MongoDB query?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 213 Views

To limit the amount of characters returned from a field in a MongoDB query, use the $substr operator within an aggregation pipeline. This operator extracts a substring from a string field based on starting position and character count. Syntax db.collection.aggregate([ { $project: { fieldName: { $substr: ["$originalField", startIndex, numberOfCharacters] } } } ]); Create Sample Data db.limitTheNumberOfCharactersDemo.insertMany([ ...

Read More

Delete specific record from an array nested within another array in MongoDB?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 250 Views

To delete a specific record from an array nested within another array in MongoDB, use the $pull operator combined with the $ positional operator to target elements in nested arrays. Syntax db.collection.update( {"parentArray.field": "value"}, { $pull: { "parentArray.$.nestedArray": { "field": "matchValue" } } } ); Sample Data Let us first create a collection with nested array documents ? db.deletingSpecificRecordDemo.insertOne({ "StudentDetails": [ { ...

Read More

MongoDB query to find data from an array inside an object?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 578 Views

To find data from an array inside an object in MongoDB, use dot notation to navigate through the nested object structure and target the specific array field. Syntax db.collection.find({"objectField.arrayField": "searchValue"}); Sample Data Let us first create a collection with documents ? db.findDataDemo.insertMany([ { "CustomerName": "John", "CustomerDetails": { "CountryName": ["AUS"], ...

Read More

MongoDB order by two fields sum?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 535 Views

To order documents by the sum of two fields in MongoDB, use the aggregation framework with $project to calculate the sum and $sort to order the results. Syntax db.collection.aggregate([ { $project: { field1: 1, field2: 1, sumField: { $add: ["$field1", "$field2"] } } }, { $sort: { sumField: 1 } } // 1 for ascending, -1 for descending ]); Sample Data db.orderByTwoFieldsDemo.insertMany([ { "Value1": 10, "Value2": 35 }, { "Value1": 12, "Value2": 5 }, ...

Read More

How do we print a variable at the MongoDB command prompt?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 2K+ Views

To print a variable at the MongoDB command prompt, you can either reference the variable name directly or use the print() function. Both methods display the variable's value in the shell. Syntax // Declaring and initializing a variable var variableName = value; // Method 1: Direct variable reference variableName; // Method 2: Using print() function print(variableName); Example 1: Integer Variable Declare and initialize an integer variable ? var myIntegerValue = 20; Print the variable using direct reference ? myIntegerValue; 20 Print ...

Read More

Retrieving the first document in a MongoDB collection?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 3K+ Views

To retrieve the first document in a MongoDB collection, use the findOne() method. This returns the first document from the collection in natural insertion order. Syntax db.collectionName.findOne(); // Store in variable and display var result = db.collectionName.findOne(); result; Sample Data db.retrieveFirstDocumentDemo.insertMany([ {"ClientName": "Robert", "ClientAge": 23}, {"ClientName": "Chris", "ClientAge": 26}, {"ClientName": "Larry", "ClientAge": 29}, {"ClientName": "David", "ClientAge": 39} ]); { "acknowledged": true, "insertedIds": [ ...

Read More

Find inside a hash MongoDB?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 325 Views

To find inside a hash (embedded document) in MongoDB, use dot notation to access nested fields. This allows you to query specific fields within embedded documents using the format "parentField.childField". Syntax db.collection.find({ "embeddedDocument.field": "value" }); Sample Data Let us create a collection with documents containing embedded ClientDetails ? db.hashDemo.insertMany([ { "ClientName": "Larry", "ClientAge": 23, "ClientDetails": { ...

Read More

How to store query result (a single document) into a variable?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 598 Views

To store a query result (a single document) into a variable in MongoDB, use the var keyword with find().limit(1) to retrieve only one document. You can then access the stored result by referencing the variable name. Syntax var variableName = db.collectionName.find().limit(1); variableName; // Display the stored result Sample Data Let us first create a collection with sample documents ? db.storeQueryResultDemo.insertMany([ {"ClientName": "Chris", "ClientAge": 23}, {"ClientName": "Robert", "ClientAge": 21}, {"ClientName": "Sam", "ClientAge": 25}, {"ClientName": "Mike", "ClientAge": 26} ...

Read More

How to get documents by tags in MongoDB?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 586 Views

To find documents by tags in MongoDB, you can use the $elemMatch operator or simple array matching. MongoDB provides several ways to query documents containing specific tags in array fields. Syntax // Using $elemMatch operator db.collection.find({Tags: { $elemMatch: { $eq: "tagValue" } }}); // Simple array matching db.collection.find({Tags: "tagValue"}); // Multiple tags using $in db.collection.find({Tags: { $in: ["tag1", "tag2"] }}); Sample Data db.getDocumentsByTagsDemo.insertMany([ {"Tags": ["Tag-1", "Tag-2", "Tag-3"]}, {"Tags": ["Tag-2", "Tag-4", "Tag-5"]}, {"Tags": ["Tag-6", "Tag-4", "Tag-3"]} ]); ...

Read More
Showing 271–280 of 749 articles
« Prev 1 26 27 28 29 30 75 Next »
Advertisements