Query Language Snippets
All Snippets
GraphQL
Read
Query with aliasing to rename fields.
query {
post1: post(id: 1) { title }
post2: post(id: 2) { title }
}
GraphQL
Read
Query with fragments for reusability.
fragment userFields on User {
id
name
email
}
query {
users {
...userFields
posts {
id
title
}
}
}
GraphQL
Read
Use directives for conditional logic (@include, @skip).
query getUser($withEmail: Boolean!) {
user(id: 5) {
name
email @include(if: $withEmail)
}
}
GraphQL
Read
Nested query with arguments.
query {
users(limit: 1) {
id
name
todos(order_by: {created_at: desc}, limit: 5) {
id
title
}
}
}
GraphQL
Read
Use inline fragments for type-specific fields.
query {
search {
__typename
... on User {
name
}
... on Post {
title
}
}
}
MongoDB
Read
Find all documents in a collection.
db.users.find();
MongoDB
Read
Find documents with a specific field value.
db.users.find({ age: 25 });
MongoDB
Read
Find documents with comparison operators ($gt, $lt, etc.).
db.users.find({ age: { $gt: 20, $lt: 30 } });
MongoDB
Read
Find documents with logical operators ($and, $or, $not).
db.users.find({
$and: [
{ age: { $gte: 18 } },
{ isActive: true }
]
});
MongoDB
Read
Find documents with IN/NOT IN operators ($in, $nin).
db.products.find({ category: { $in: ["book", "magazine"] } });
MongoDB
Read
Find documents with regular expressions.
db.users.find({ name: /john/i });
MongoDB
Read
Use $lookup for left outer join between collections.
db.orders.aggregate([
{
$lookup: {
from: "users",
localField: "userId",
foreignField: "_id",
as: "user"
}
}
]);