Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不知道我的集合中的属性名称是什么。
DBCollection objDBC = db.getCollection(collectionName); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put(attributeName, attributeValue); DBCursor cursor = objDBC.find(searchQuery);
现在从 DBCursor 如何检索所有属性的值?
DBCursor实际上是一个结果迭代器,每个结果元素都是一个DBObject,因此可以转换为一个映射;要检索所有值,您可以执行以下操作:
while(cursor.hasNext()) { DBObject resultElement = cursor.next(); Map resultElementMap = resultElement.toMap(); Collection resultValues = resultElementMap.values(); //Do something with the values }