本文整理汇总了Java中com.mongodb.client.model.Sorts类的典型用法代码示例。如果您正苦于以下问题:Java Sorts类的具体用法?Java Sorts怎么用?Java Sorts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sorts类属于com.mongodb.client.model包,在下文中一共展示了Sorts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGardenLocationsAsJson
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
/**
* Takes `uploadID` and returns all bed names as a json format string
* @param uploadID - the year that the data was uploaded
* @return String representation of json with all bed names
*/
public String getGardenLocationsAsJson(String uploadID){
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadID", uploadID)), //!! Order is important here
Aggregates.group("$gardenLocation"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<Document> listDoc = new ArrayList<>();
for (Document doc : documents) {
listDoc.add(doc);
}
listDoc.sort(new BedComparator());
return JSON.serialize(listDoc);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:23,代码来源:PlantController.java
示例2: averageAge
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Test
public void averageAge() {
AggregateIterable<Document> documents
= userDocuments.aggregate(
Arrays.asList(
Aggregates.group("$company",
Accumulators.avg("averageAge", "$age")),
Aggregates.sort(Sorts.ascending("_id"))
));
List<Document> docs = intoList(documents);
assertEquals("Should be three companies", 3, docs.size());
assertEquals("Frogs, Inc.", docs.get(0).get("_id"));
assertEquals(37.0, docs.get(0).get("averageAge"));
assertEquals("IBM", docs.get(1).get("_id"));
assertEquals(37.0, docs.get(1).get("averageAge"));
assertEquals("UMM", docs.get(2).get("_id"));
assertEquals(25.0, docs.get(2).get("averageAge"));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:20,代码来源:MongoSpec.java
示例3: listUploadIds
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
/**
*
* @return a date-sorted List of all the distinct uploadIds in the DB
*/
public static List<String> listUploadIds(MongoDatabase database) {
MongoCollection<Document> plantCollection = database.getCollection("plants");
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.group("$uploadId"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<String> lst = new LinkedList<>();
for(Document d: documents) {
lst.add(d.getString("_id"));
}
return lst;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:20,代码来源:ExcelParser.java
示例4: getServerQuery
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
private static List<Bson> getServerQuery(Bson filter) {
final List<Bson> pipeline = new ArrayList<>(6);
if (filter != ALL) {
pipeline.add(Aggregates.match(filter));
}
pipeline.add(Aggregates.unwind("$deployments", new UnwindOptions().preserveNullAndEmptyArrays(true)));
pipeline.add(Aggregates.lookup(Collections.APPLICATIONS, "deployments.applicationId", "id", "applications"));
pipeline.add(Aggregates.unwind("$applications", new UnwindOptions().preserveNullAndEmptyArrays(true)));
pipeline.add(Aggregates.group(
new Document().append("hostname", "$hostname").append("environment", "$environment"),
new BsonField("fqdn", new Document("$first", "$fqdn")),
new BsonField("description", new Document("$first", "$description")),
new BsonField("os", new Document("$first", "$os")),
new BsonField("network", new Document("$first", "$network")),
new BsonField("meta", new Document("$first", "$meta")),
new BsonField("attributes", new Document("$first", "$attributes")),
new BsonField("applications", new Document("$push", "$applications")),
new BsonField("deployments", new Document("$push", "$deployments"))));
pipeline.add(Aggregates.sort(Sorts.ascending("_id")));
return pipeline;
}
示例5: listPlants
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
/**
* List all plants within the database, filtered by uploadId, gardenLocation and commonName
* @param queryParams
* @param uploadId
* @return
*/
public String listPlants(Map<String, String[]> queryParams, String uploadId) {
if (!ExcelParser.isValidUploadId(db, uploadId))
return "null";
//Create a filter based on query params
Document filterDoc = new Document();
filterDoc.append("uploadId", uploadId);
if (queryParams.containsKey("gardenLocation")) {
String location =(queryParams.get("gardenLocation")[0]);
filterDoc = filterDoc.append("gardenLocation", location);
}
if (queryParams.containsKey("commonName")) {
String commonName =(queryParams.get("commonName")[0]);
filterDoc = filterDoc.append("commonName", commonName);
}
FindIterable<Document> matchingPlants = plantCollection.find(filterDoc);
matchingPlants.sort(Sorts.ascending("commonName", "cultivar"));
return JSON.serialize(matchingPlants);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:32,代码来源:PlantController.java
示例6: ageCounts
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Test
public void ageCounts() {
AggregateIterable<Document> documents
= userDocuments.aggregate(
Arrays.asList(
/*
* Groups data by the "age" field, and then counts
* the number of documents with each given age.
* This creates a new "constructed document" that
* has "age" as it's "_id", and the count as the
* "ageCount" field.
*/
Aggregates.group("$age",
Accumulators.sum("ageCount", 1)),
Aggregates.sort(Sorts.ascending("_id"))
)
);
List<Document> docs = intoList(documents);
assertEquals("Should be two distinct ages", 2, docs.size());
assertEquals(docs.get(0).get("_id"), 25);
assertEquals(docs.get(0).get("ageCount"), 1);
assertEquals(docs.get(1).get("_id"), 37);
assertEquals(docs.get(1).get("ageCount"), 2);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:25,代码来源:MongoSpec.java
示例7: listSuites
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Override
public List<Suite> listSuites(DBKey dbKey) throws StorageException {
MongoCollection<Document> metadata = getMetadataCollection(dbKey);
LOGGER.debug("Fetching all suites for company: `{}`, project: `{}`.", dbKey.getCompany(),
dbKey.getProject());
final FindIterable<Document> found = metadata
.find()
.sort(Sorts.descending(SUITE_VERSION_PARAM_NAME));
return FluentIterable.from(found).transform(new Function<Document, Suite>() {
@Override
public Suite apply(Document result) {
return new DocumentConverter(result).toSuite();
}
}).toList();
}
示例8: serie
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Override
public Timeserie serie(String name) {
Set<Data> results = StreamSupport
.stream(timeseries
.find(Filters.eq("type", name))
.sort(Sorts.ascending("timestamp_hour"))
.limit(3)
.map(doc -> {
LocalDateTime hour = LocalDateTime.ofEpochSecond(((Date) doc.get("timestamp_hour")).getTime() / 1000, 0, ZoneOffset.UTC);
Map<String, Long> values = (Map<String, Long>) doc.get("values");
List<Data> mapped = values.entrySet().stream().map(elt -> Data.of(hour.plusMinutes(Long.valueOf(elt.getKey())), elt.getValue()))
.collect(Collectors.toList());
return mapped;
}).spliterator(), true).flatMap(elts -> elts.stream()).collect(TreeSet::new, Set::add, (left, right) -> {
left.addAll(right);
});
Timeserie timeserie = new Timeserie();
timeserie.addAll(results);
return timeserie;
}
示例9: getCommonNamesJSON
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
/**
* Get a json containing a list of commonNames sorted by common name
* @param uploadID
* @return
*/
public String getCommonNamesJSON(String uploadID){
if (!ExcelParser.isValidUploadId(db, uploadID))
return "null";
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadId", uploadID)), //!! Order is important here
Aggregates.group("$commonName"),
Aggregates.sort(Sorts.ascending("commonName"))
));
return JSON.serialize(documents);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:19,代码来源:PlantController.java
示例10: sort
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Override
public Bson sort() {
if ((isBlank(caller) || isRegex(caller)) && (isBlank(callee) || isRegex(callee))) {
return null;
}
return Sorts.ascending("millis");
}
示例11: getStatuses
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Deprecated
public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) {
// consider month switch during data extraction if will be used
switchCollection(from);
return thisCollection.find(and(
eq("environmentName", environmentName),
gte("updated", from),
lte("updated", to),
eq("resource.resourceId", resourceId))
)
.sort(Sorts.ascending("updated"))
.map(DocumentMapper::resourceStatusFromDocument)
.into(new ArrayList<>());
}
示例12: get
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
public List<Message> get(OfflineMessagesMeta meta) {
Document query = new Document("topic", meta.topic).append("msgid", new Document().append("$gt", meta.start).append("$lte", meta.end));
FindIterable<Document> list = this.mongo.find(query).sort(Sorts.ascending("msgid"));
List<Message> messages = new ArrayList<>();
for (Document doc : list) {
messages.add(new Message(doc.getString("topic"), doc.getLong("msgid"), ((Binary) doc.get("msg")).getData()));
}
return messages;
}
示例13: getGardenLocationsAsJson
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
public String getGardenLocationsAsJson(String uploadID) {
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadId", uploadID)), //!! Order is important here
Aggregates.group("$gardenLocation"),
Aggregates.sort(Sorts.ascending("_id"))
));
return JSON.serialize(documents);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:11,代码来源:PlantController.java
示例14: listUploadIds
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
/**
*
* @return a sorted JSON array of all the distinct uploadIds in the DB
*/
public String listUploadIds() {
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.group("$uploadId"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<String> lst = new LinkedList<>();
for(Document d: documents) {
lst.add(d.getString("_id"));
}
return JSON.serialize(lst);
// return JSON.serialize(plantCollection.distinct("uploadId","".getClass()));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:19,代码来源:PlantController.java
示例15: over25SortedByName
import com.mongodb.client.model.Sorts; //导入依赖的package包/类
@Test
public void over25SortedByName() {
FindIterable<Document> documents
= userDocuments.find(gt("age", 25))
.sort(Sorts.ascending("name"));
List<Document> docs = intoList(documents);
assertEquals("Should be 2", 2, docs.size());
assertEquals("First should be Jamie", "Jamie", docs.get(0).get("name"));
assertEquals("Second should be Pat", "Pat", docs.get(1).get("name"));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:11,代码来源:MongoSpec.java