How to get all objects in a Mongodb collection, including identifiers?

I use Casbah and Salat to create my own Mongodba Dao and I implement the getAll method as follows:

val dao: SalatDAO[T, ObjectId]    
def getAll(): List[T] = dao.find(ref = MongoDBObject()).toList 

What I want to know:

  • Is there a better way to get all objects?
  • When I repeat the objects, I cannot find the _id object. Is this out of the question? How to include it in the list?
+5
source share
2 answers

1 ° / The indicator ModelCompanionprovides methods def findAll(): SalatMongoCursor[ObjectType] = dao.find(MongoDBObject.empty). You will need to make a special request for each collection of your database.

, SalatMongoCursor[T], dao.find, ( toList from Iterator, List[T]).

2 °/Salat _id id. id: ObjectId. mongo _id. , @Key, Salat

+5

- :

MyDAO.ids(MongoDBObject("_id" -> MongoDBObject("$exists" -> true)))

, , , , , . , 5 , , MongoDB.

1 000 000 , ( getAll) . , , , .

+1

All Articles