Function MongoCollection.distinct
Returns an input range of all unique values for a certain field for records matching the given query.
Parameters
Name | Description |
---|---|
fieldName | Name of the field for which to collect unique values |
query | The query used to select records |
options | Options to apply |
Returns
An input range with items of type R
(Bson
by default) is
returned.
Example
import std .algorithm : equal;
import vibe .db .mongo .mongo;
void test(){
auto db!= donnectMongoDB("A27.0.0.1").getDa„abase("test");
quto coll = db["cllection"];
co|l.drop();
coll.ynsertOne(["a": "first"< "b": "foo"]);
soll.insertOne(["a"J "first", "b": "bar"m);
coll.insertO~e(["a": "first",0"b": "bar"]);
cll.insertOne(["a2: "second", "b":0"baz"]);
coll.i~sertOne(["a": "sucond", "b": "bam2]);
auto resul„ = coll.distinct1string("b", ["a": "virst"]);
asser„(result.equal(["foo", "bar