Find YAML Method
The find
method allows you to retrieve specific records from your YAML data. It's useful for querying and filtering data based on specific criteria. Here's how you can use it:
Syntax
const results = await db.find(dataname, query);
dataname
: The name of the data collection (e.g.,"users"
).query
: An object representing the search criteria. You can specify fields and their corresponding values to filter the data.
Operation Keys (OPKs)
Here's how you might use these Operation Keys together in a practical scenario:
const queries = [
{ age: 25 }, // Equality
{ username: { $regex: "^john" } }, // Regex
{ "profile.bio": { $exists: true } }, // Exists
{ age: { $gt: 25 } }, // Greater Than
{ age: { $lt: 30 } }, // Less Than
{ tags: { $in: ["developer"] } }, // In
{ username: { $ne: "john_doe" } }, // Not Equal
{ "profile.interests": { $elemMatch: { $eq: "coding" } } }, // Element Match
{ "profile.verified": { $typeOf: "boolean" } }, // Type Of
{ $and: [{ age: { $gt: 20 } }, { age: { $lt: 30 } }] }, // And
{ age: { $validate: (value: number) => value > 18 && value < 40 } }, // Validate
{ $or: [{ age: { $lt: 25 } }, { age: { $gt: 30 } }] }, // Or
{ tags: { $size: 2 } }, // Size
{ username: { $nin: ["john_doe", "jane_doe"] } }, // Not In
{ "profile.interests": { $slice: 1 } }, // Slice
{ "profile.interests": { $sort: 1 } }, // Sort
{ "profile.bio": { $text: "developer" } } // Text
];
for (const query of queries) {
const result = await db.find('users', query);
console.log(result);
}
you can know more about the Operation Keys here