I'm trying to filter out the password
field when querying a document from MongoDB with ReactiveMongo:
val projection = Json.obj("password" -> 0)
def find(selector: JsValue, projection: Option[JsValue]) = {
val query = collection.genericQueryBuilder.query(selector)
projection.map(query.projection(_))
query.cursor[JsValue].collect[Vector](perPage).transform(
success => success,
failure => failure match {
case e: LastError => DaoException(e.message, Some(DATABASE_ERROR))
}
)
}
The code above has no effect... I also get the password
field. If I try the following from the mongo client, then it works and password
is not returned:
db.users.find( { username: 'j3d' }, { password:0} )
Am I missing something?