Skip to main content

MongoDb

Type Alias MongoDb 

Source
pub type MongoDb = Builder<MongoDbDialect>;
Expand description

A MongoDB builder: compiles to operation documents (JSON).

PHP: Utopia\Query\Builder\MongoDB.

use utopia_query::Query;
use utopia_query::builder::MongoDb;

let statement = MongoDb::new()
    .from("users", "")
    .select(["name"])
    .filter([Query::greater_than("age", 18)])
    .sort_desc("age", None)
    .limit(10)
    .build()?;
assert_eq!(
    statement.query,
    r#"{"collection":"users","operation":"find","filter":{"age":{"$gt":"?"}},"projection":{"name":1,"_id":0},"sort":{"age":-1},"limit":10}"#
);
assert_eq!(statement.bindings, vec![18.into()]);
use Utopia\Query\Builder\MongoDB;
use Utopia\Query\Query;

$statement = (new MongoDB())
    ->from('users')
    ->select(['name'])
    ->filter([Query::greaterThan('age', 18)])
    ->sortDesc('age')
    ->limit(10)
    ->build();
echo $statement->query, "\n";
// {"collection":"users","operation":"find","filter":{"age":{"$gt":"?"}},"projection":{"name":1,"_id":0},"sort":{"age":-1},"limit":10}

Aliased Typeยง

pub struct MongoDb { /* private fields */ }