本文整理汇总了Java中org.bson.Document.put方法的典型用法代码示例。如果您正苦于以下问题:Java Document.put方法的具体用法?Java Document.put怎么用?Java Document.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.Document
的用法示例。
在下文中一共展示了Document.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteOne
import org.bson.Document; //导入方法依赖的package包/类
/**
* Deletes a single document matching a query specifier.
*
* @param query The query specifier.
* @return A task that can be resolved upon completion of the request.
*/
public Task<Document> deleteOne(final Document query) {
Document doc = new Document(Parameters.QUERY, query);
doc.put(Parameters.DATABASE, _database._dbName);
doc.put(Parameters.SINGLE_DOCUMENT, true);
doc.put(Parameters.COLLECTION, _collName);
return _database._client._stitchClient.executeServiceFunction(
"deleteOne", _database._client._service, doc
).continueWith(new Continuation<Object, Document>() {
@Override
public Document then(@NonNull Task<Object> task) throws Exception {
if (task.isSuccessful()) {
return (Document) task.getResult();
} else {
Log.e(TAG, "Error while executing function", task.getException());
throw task.getException();
}
}
});
}
示例2: deleteMany
import org.bson.Document; //导入方法依赖的package包/类
/**
* Deletes many document matching a query specifier.
*
* @param query The query specifier.
* @return A task that can be resolved upon completion of the request.
*/
public Task<Document> deleteMany(final Document query) {
final Document doc = new Document(Parameters.QUERY, query);
doc.put(Parameters.DATABASE, _database._dbName);
doc.put(Parameters.COLLECTION, _collName);
doc.put(Parameters.SINGLE_DOCUMENT, false);
return _database._client._stitchClient.executeServiceFunction(
"deleteMany", _database._client._service, doc
).continueWith(new Continuation<Object, Document>() {
@Override
public Document then(@NonNull Task<Object> task) throws Exception {
if (task.isSuccessful()) {
return (Document) task.getResult();
} else {
Log.e(TAG, "Error while executing function", task.getException());
throw task.getException();
}
}
});
}
示例3: persistMigration
import org.bson.Document; //导入方法依赖的package包/类
private void persistMigration(String version,
String description,
String author,
String started,
String finished,
MigrationStatus status,
String failureMessage) {
Document document = new Document();
document.put("version", version);
document.put("description", description);
document.put("author", Optional.ofNullable(author).orElse(Migration.DEFAULT_AUTHOR));
document.put("started", Optional.ofNullable(started).map(DateTime::parse).map(DateTime::toDate).orElse(null));
document.put("finished", Optional.ofNullable(finished).map(DateTime::parse).map(DateTime::toDate).orElse(null));
document.put("status", status.name());
document.put("failureMessage", failureMessage);
this.collection.insertOne(document);
}
示例4: getDatesFromDB
import org.bson.Document; //导入方法依赖的package包/类
public ArrayList<Date> getDatesFromDB(String uploadID){
Document filter = new Document();
filter.put("uploadId", uploadID);
ArrayList<Date> dates = new ArrayList<Date>();
//Get all
FindIterable doc = plantCollection.find(filter);
Iterator iterator = doc.iterator();
while(iterator.hasNext()) {
Document result = (Document) iterator.next();
//Get metadata.rating array
List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("visits");
//Loop through all of the entries within the array, counting like=true(like) and like=false(dislike)
for(int i = 0; i < ratings.size(); i++){
Document d = ratings.get(i);
dates.add(((ObjectId) d.get("visit")).getDate());
}
}
return dates;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:26,代码来源:GardenCharts.java
示例5: getDeviceInfo
import org.bson.Document; //导入方法依赖的package包/类
/**
* @return A {@link Document} representing the information for this device
* from the context of this app.
*/
private Document getDeviceInfo() {
final Document info = new Document();
if (hasDeviceId()) {
info.put(DeviceFields.DEVICE_ID, getDeviceId());
}
final String packageName = _context.getPackageName();
final PackageManager manager = _context.getPackageManager();
try {
final PackageInfo pkgInfo = manager.getPackageInfo(packageName, 0);
info.put(DeviceFields.APP_VERSION, pkgInfo.versionName);
} catch (final PackageManager.NameNotFoundException e) {
Log.e(TAG, "Error while getting info for app package", e);
throw new StitchException.StitchClientException(e);
}
info.put(DeviceFields.APP_ID, packageName);
info.put(DeviceFields.PLATFORM, PLATFORM);
info.put(DeviceFields.PLATFORM_VERSION, Build.VERSION.RELEASE);
return info;
}
示例6: persistMigration
import org.bson.Document; //导入方法依赖的package包/类
private void persistMigration(String version,
String description,
String author,
String started,
String finished,
MigrationStatus status,
String failureMessage) {
Document document = new Document();
document.put("version", version);
document.put("description", description);
document.put("author", Optional.ofNullable(author).orElse(Migration.DEFAULT_AUTHOR));
document.put("started", Optional.ofNullable(started).map(DateTime::parse).map(DateTime::toDate).orElse(null));
document.put("finished", Optional.ofNullable(finished).map(DateTime::parse).map(DateTime::toDate).orElse(null));
document.put("status", status.name());
document.put("failureMessage", failureMessage);
this.database.getCollection(SCHEMA_VERSION_COLLECTION).insertOne(document);
}
示例7: insertOne
import org.bson.Document; //导入方法依赖的package包/类
/**
* Inserts a single document.
*
* @param document The document to insert.
* @return A task that can be resolved upon completion of the request.
*/
public Task<Document> insertOne(final Document document) {
final Document doc = new Document("document", document);
doc.put(Parameters.DATABASE, _database._dbName);
doc.put(Parameters.COLLECTION, _collName);
return _database._client._stitchClient.executeServiceFunction(
"insertOne", _database._client._service, doc
).continueWith(new Continuation<Object, Document>() {
@Override
public Document then(@NonNull Task<Object> task) throws Exception {
if (task.isSuccessful()) {
return (Document) task.getResult();
} else {
Log.e(TAG, "Error while executing function", task.getException());
throw task.getException();
}
}
});
}
示例8: getRegistrationPayload
import org.bson.Document; //导入方法依赖的package包/类
/**
* Create a payload exclusively for {@link StitchClient#register(String, String)}
*
* @return a payload containing the email and password of the registrant
*/
public Document getRegistrationPayload() {
final Document doc = new Document();
doc.put(KEY_EMAIL, this.email);
doc.put(KEY_PASSWORD, this.password);
return doc;
}
示例9: clearUpload
import org.bson.Document; //导入方法依赖的package包/类
/**
* Deletes all data associated with an uploadId
* @param uploadId
*/
public static void clearUpload(String uploadId, MongoDatabase database)
{
MongoCollection<Document> plantCollection = database.getCollection("plants");
MongoCollection<Document> commentCollection = database.getCollection("comment");
MongoCollection<Document> bedCollection = database.getCollection("beds");
Document uploadIdFilter = new Document();
uploadIdFilter.put("uploadId", uploadId);
plantCollection.deleteMany(uploadIdFilter);
commentCollection.deleteMany(uploadIdFilter);
bedCollection.deleteMany(uploadIdFilter);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:18,代码来源:ExcelParser.java
示例10: heartbeatAndUpdateCustomAttrs
import org.bson.Document; //导入方法依赖的package包/类
@Override
public Optional<T> heartbeatAndUpdateCustomAttrs(final T item, final Map<String, Object> attrs) {
validateHeartbeat(item);
final Document query = new Document();
query.put("_id", new ObjectId(item.getId()));
query.put("status", OkraStatus.PROCESSING.name());
query.put("heartbeat", DateUtil.toDate(item.getHeartbeat()));
final Document update = new Document();
update.put("$set", new Document("heartbeat", new Date()));
if (attrs != null && !attrs.isEmpty()) {
attrs.forEach((key, value) -> update.append("$set", new Document(key, value)));
}
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document result = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(query, update, options);
if (result == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, result));
}
示例11: count
import org.bson.Document; //导入方法依赖的package包/类
/**
* Counts the number of documents matching a query up to the specified limit.
*
* @param query The query specifier.
* @return A task containing the number of matched documents that can be resolved upon completion
* of the request.
*/
public Task<Long> count(final Document query, final Document projection) {
Document doc = new Document(Parameters.QUERY, query);
doc.put(Parameters.DATABASE, _database._dbName);
doc.put(Parameters.COLLECTION, _collName);
if (projection != null) {
doc.put(Parameters.PROJECT, projection);
}
return _database._client._stitchClient.executeServiceFunction(
"count", _database._client._service, doc
).continueWith(new Continuation<Object, Long>() {
@Override
public Long then(@NonNull Task<Object> task) throws Exception {
if (task.isSuccessful()) {
final Object result = task.getResult();
if (result instanceof Integer) {
return Long.valueOf((Integer) result);
}
return (Long) result;
} else {
Log.e(TAG, "Error while executing function", task.getException());
throw task.getException();
}
}
});
}
示例12: toDocument
import org.bson.Document; //导入方法依赖的package包/类
/**
* @return The provider info as a serializable document.
*/
@Override
public Document toDocument() {
final Document doc = super.toDocument();
final Document config = (Document) doc.get(PushProviderInfo.Fields.CONFIG);
config.put(Fields.SENDER_ID, _senderId);
return doc;
}
示例13: getAuthRequest
import org.bson.Document; //导入方法依赖的package包/类
/**
* @param request Arbitrary document for authentication
* @return A {@link Document} representing all information required for
* an auth request against a specific provider.
*/
private Document getAuthRequest(final Document request) {
final Document options = new Document();
options.put(AuthFields.DEVICE, getDeviceInfo());
request.put(AuthFields.OPTIONS, options);
return request;
}
示例14: getFeedbackForPlantByPlantID
import org.bson.Document; //导入方法依赖的package包/类
/**
* @param plantID The plant to get feedback of
* @param uploadID Dataset to find the plant
* @return JSON for the number of comments, likes, and dislikes
* Of the form:All
* {
* commentCount: number
* likeCount: number
* dislikeCount: number
* }
*/
public String getFeedbackForPlantByPlantID(String plantID, String uploadID) {
Document out = new Document();
Document filter = new Document();
filter.put("commentOnPlant", plantID);
filter.put("uploadId", uploadID);
long comments = commentCollection.count(filter);
long likes = 0;
long dislikes = 0;
//Get a plant by plantID
FindIterable doc = plantCollection.find(new Document().append("id", plantID).append("uploadId", uploadID));
Iterator iterator = doc.iterator();
if (iterator.hasNext()) {
Document result = (Document) iterator.next();
//Get metadata.rating array
List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
//Loop through all of the entries within the array, counting like=true(like) and like=false(dislike)
for (Document rating : ratings) {
if (rating.get("like").equals(true))
likes++;
else if (rating.get("like").equals(false))
dislikes++;
}
}
out.put("commentCount", comments);
out.put("likeCount", likes);
out.put("dislikeCount", dislikes);
return JSON.serialize(out);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:49,代码来源:PlantController.java
示例15: getFeedbackForPlantByPlantID
import org.bson.Document; //导入方法依赖的package包/类
/**
*
* @param plantID The plant to get feedback of
* @param uploadID Dataset to find the plant
*
* @return JSON for the number of interactions of a plant (likes + dislikes + comments)
* Of the form:
* {
* interactionCount: number
* }
*/
public String getFeedbackForPlantByPlantID(String plantID, String uploadID) {
long comments = 0;
long likes = 0;
long dislikes = 0;
long interactions = 0;
Document out = new Document();
FindIterable document = plantCollection.find(new Document().append("id", plantID).append("uploadID", uploadID));
Iterator iterator = document.iterator();
if(iterator.hasNext()){
Document result = (Document) iterator.next();
//Get metadat.comments array
List<Document> plantComments = (List<Document>) ((Document) result.get("metadata")).get("comments");
comments = plantComments.size();
//Get metadata.rating array
List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
//Loop through all of the entries within the array, counting like=true(like) and like=false(dislike)
for(Document rating : ratings)
{
if(rating.get("like").equals(true))
likes++;
else if(rating.get("like").equals(false))
dislikes++;
}
}
interactions = likes + dislikes + comments;
out.put("interactionCount", interactions);
return JSON.serialize(out);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:50,代码来源:PlantController.java