vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

MongoCollection.findOne - multiple declarations

Function MongoCollection.findOne

auto findOne(R, T, U) (
  T query,
  U returnFieldSelector,
  QueryFlags flags
);

Function MongoCollection.findOne

Queries the collection for existing documents.

auto findOne(R, T, U) (
  T query,
  U projection,
  FindOptions options = FindOptions.init
)
if (!is(U == FindOptions));

Returns

By default, a Bson value of the matching document is returned, or Bson(null) when no document matched. For types R that are not Bson, the returned value is either of type R, or of type , if R is not a reference/pointer type.

The projection parameter limits what fields are returned by the database, see projection documentation linked below.

Throws

Exception if a DB communication error or a query error occurred.

See Also

- Querying: http://www.mongodb.org/display/DOCS/Querying - Projection: https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/#std-label-projections - find

Example

import vibe.db.mongo.mongo;

void test()
{
	auto coll = connectMongoDB("127.0.0.1").getCollection("test");
	// find documents with status == "A"
	auto x = coll.findOne(["status": "A"], ["status": true, "otherField": true]);
	// x now only contains _id (implicit, unless you make it `false`), status and otherField
}

Function MongoCollection.findOne

Queries the collection for existing documents.

auto findOne(R, T) (
  T query,
  FindOptions options = FindOptions.init
);

Returns

By default, a Bson value of the matching document is returned, or Bson(null) when no document matched. For types R that are not Bson, the returned value is either of type R, or of type , if R is not a reference/pointer type.

Throws

Exception if a DB communication error or a query error occurred.

See Also

- http://www.mongodb.org/display/DOCS/Querying - find

Authors

Sönke Ludwig

Copyright

© 2012-2016 Sönke Ludwig

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.