本文整理汇总了Java中org.bson.Document.remove方法的典型用法代码示例。如果您正苦于以下问题:Java Document.remove方法的具体用法?Java Document.remove怎么用?Java Document.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.Document
的用法示例。
在下文中一共展示了Document.remove方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBookingsByUser
import org.bson.Document; //导入方法依赖的package包/类
@Override
public List<String> getBookingsByUser(String user) {
List<String> bookings = new ArrayList<String>();
if(logger.isLoggable(Level.FINE)){
logger.fine("getBookingsByUser : " + user);
}
try (MongoCursor<Document> cursor = booking.find(eq("customerId", user)).iterator()){
while (cursor.hasNext()){
Document tempBookings = cursor.next();
Date dateOfBooking = (Date)tempBookings.get("dateOfBooking");
tempBookings.remove("dateOfBooking");
tempBookings.append("dateOfBooking", dateOfBooking.toString());
if(logger.isLoggable(Level.FINE)){
logger.fine("getBookingsByUser cursor data : " + tempBookings.toJson());
}
bookings.add(tempBookings.toJson());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return bookings;
}
示例2: doTranslate
import org.bson.Document; //导入方法依赖的package包/类
private Map<String, List<String>> doTranslate(Set<String> tokens) {
MongoCollection<Document> lexColl = getLexCollection();
FindIterable<Document> lexs = lexColl.find(Filters.in(TERM_FIELD, tokens));
Map<String, List<String>> res = new HashMap<>();
for (Document doc : lexs) {
Document tr = (Document) doc.get(TRANSLATION_FIELD);
if (tr != null) {
tr.remove(NULL_VALUE);
res.put(doc.getString(TERM_FIELD), getRelevantTranslations((Map) tr));
}
}
return res;
}
示例3: register
import org.bson.Document; //导入方法依赖的package包/类
@POST @Consumes(MediaType.APPLICATION_JSON)
public Response register(@NotNull @Valid User user) {
long level = MongoDBs.users().count();
if (level > Globals.LIMIT_REGISTER) {
return Response.status(Response.Status.FORBIDDEN)
.entity(new Failure("Rebase suspends the registration service currently"))
.build();
}
Document document = new Document(User.USERNAME, user.username)
.append(User.PASSWORD, Hashes.sha1(user.password))
.append(User.NAME, user.name)
.append(User.EMAIL, user.email)
.append(User.DESCRIPTION, user.description)
.append(User.AUTHORIZATION, Authorizations.newInstance(user.username))
.append(User.CREATED_AT, new Date());
MongoDBs.users().insertOne(document);
Document result = new Document(document);
result.remove(User.PASSWORD);
return Response.created(URIs.create("users", user.username))
.entity(result)
.build();
}
示例4: seed
import org.bson.Document; //导入方法依赖的package包/类
protected MongoStorageCoordinates seed(Document... documents) {
String databaseName = createDatabaseName();
String collectionName = createCollectionName();
MongoCollection<Document> mongoCollection =
getMongoClient().getDatabase(databaseName).getCollection(collectionName);
mongoCollection
.insertMany(Lists.newArrayList(documents))
.timeout(10, SECONDS)
.toBlocking()
.single();
for (Document document : documents) {
document.remove("_id");
}
assertThat(
"Failed to seed the given documents!",
mongoCollection.count().toBlocking().single(),
is((long) documents.length));
return new MongoStorageCoordinates(databaseName, collectionName);
}
示例5: find
import org.bson.Document; //导入方法依赖的package包/类
/**
* 查找指定条数的数据
*/
public <T> List<T> find(String collectionName, Integer pageNumber, Integer pageSize, Class<T> clazz) {
MongoCollection collection = mongoDatabase.getCollection(collectionName);
List<T> list = new ArrayList<>();
if (collection == null) {
return list;
}
FindIterable findIterable = collection.find();
if (pageSize != null && pageSize >= 0) {
if (pageNumber != null && pageNumber >= 1) {
findIterable = findIterable.skip((pageNumber - 1) * pageSize);
}
findIterable = findIterable.limit(pageSize);
}
Iterator<Document> iterator = findIterable.iterator();
while (iterator.hasNext()) {
Document document = iterator.next();
document.remove("_id");
T t = JSON.parseObject(document.toJson(), clazz);
list.add(t);
}
return list;
}
示例6: transform
import org.bson.Document; //导入方法依赖的package包/类
public <T> T transform(Class<T> clazz, Document document) {
try {
document.remove("_id");
return objectMapper.readValue(document.toJson(), clazz);
} catch (Exception e) {
throw new TransformerException("Failed to deserialise document!", e);
}
}
示例7: getCustomerByUsername
import org.bson.Document; //导入方法依赖的package包/类
@Override
public String getCustomerByUsername(String username) {
Document customerDoc = customer.find(eq("_id", username)).first();
if (customerDoc != null) {
customerDoc.remove("password");
customerDoc.append("password", null);
}
return customerDoc.toJson();
}
示例8: insertEvent
import org.bson.Document; //导入方法依赖的package包/类
/**
* This method inserts an {@link Event} in the database
*
* @param event {@link Event} to insert into database
* @param callback {@link DatabaseWriterCallback} called after inserting
* @throws NullPointerException if event or callback is null
* @see DatabaseWriter#mongoCollection
* @see DatabaseWriter#LOCATION_FIELD
* @see DatabaseWriter#METRICS_LOGGER
* @see DatabaseWriter#mapper
*/
public void insertEvent(Event event, DatabaseWriterCallback callback) {
Objects.requireNonNull(event);
Objects.requireNonNull(callback);
try {
long start = System.currentTimeMillis();
Document document = Document.parse(mapper.writeValueAsString(event));
document.remove("start");
document.remove("end");
document.remove(LOCATION_FIELD);
document.append("start", event.getStart().getTime());
document.append("end", event.getEnd().getTime());
if (event.getLocation().length == 1) {
document.append(LOCATION_FIELD, new Point(new Position(
event.getLocation()[0].getLongitude(), event.getLocation()[0].getLatitude())));
} else {
List<Position> positions = Arrays.stream(event.getLocation())
.map(p -> new Position(p.getLongitude(), p.getLatitude())).collect(Collectors.toList());
document.append(LOCATION_FIELD, new Polygon(positions));
}
this.mongoCollection.insertOne(document, (result, t) -> callback.onResult(t));
long time = System.currentTimeMillis() - start;
METRICS_LOGGER.log("time_dbwriter_" + event.getSource(), time);
} catch (JsonProcessingException e) {
LOGGER.error("Invalid event format: event not inserted in database.");
}
}
示例9: sessionWrapperWithNoMaxIntervalShouldFallbackToDefaultValues
import org.bson.Document; //导入方法依赖的package包/类
@Test
public void sessionWrapperWithNoMaxIntervalShouldFallbackToDefaultValues() {
// given
MongoSession toSerialize = new MongoSession();
DBObject dbObject = convertToDBObject(toSerialize);
Document document = new Document(dbObject.toMap());
document.remove("interval");
// when
MongoSession convertedSession = this.mongoSessionConverter.convert(document);
// then
assertThat(convertedSession.getMaxInactiveInterval()).isEqualTo(Duration.ofMinutes(30));
}
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:16,代码来源:JdkMongoSessionConverterTest.java
示例10: removeInfoFromConfigs
import org.bson.Document; //导入方法依赖的package包/类
/**
* @param info The push provider info to no longer persist.
*/
protected synchronized void removeInfoFromConfigs(final PushProviderInfo info) {
final Document configs = Document.parse(_globalPreferences.getString(PREF_CONFIGS, "{}"));
configs.remove(info.getService());
_globalPreferences.edit().putString(PREF_CONFIGS, configs.toJson()).apply();
}
示例11: getFlightBySegment
import org.bson.Document; //导入方法依赖的package包/类
@Override
protected List<String> getFlightBySegment(String segment, Date deptDate){
try {
JSONObject segmentJson = (JSONObject) new JSONParser().parse(segment);
MongoCursor<Document> cursor;
if(deptDate != null) {
if(logger.isLoggable(Level.FINE)){
logger.fine("getFlghtBySegment Search String : " + new BasicDBObject("flightSegmentId", segmentJson.get("_id")).append("scheduledDepartureTime", deptDate).toJson());
}
cursor = flight.find(new BasicDBObject("flightSegmentId", segmentJson.get("_id")).append("scheduledDepartureTime", deptDate)).iterator();
} else {
cursor = flight.find(eq("flightSegmentId", segmentJson.get("_id"))).iterator();
}
List<String> flights = new ArrayList<String>();
try{
while(cursor.hasNext()){
Document tempDoc = cursor.next();
if(logger.isLoggable(Level.FINE)){
logger.fine("getFlghtBySegment Before : " + tempDoc.toJson());
}
Date deptTime = (Date)tempDoc.get("scheduledDepartureTime");
Date arvTime = (Date)tempDoc.get("scheduledArrivalTime");
tempDoc.remove("scheduledDepartureTime");
tempDoc.append("scheduledDepartureTime", deptTime.toString());
tempDoc.remove("scheduledArrivalTime");
tempDoc.append("scheduledArrivalTime", arvTime.toString());
if(logger.isLoggable(Level.FINE)){
logger.fine("getFlghtBySegment after : " + tempDoc.toJson());
}
flights.add(tempDoc.append("flightSegment", segmentJson).toJson());
}
}finally{
cursor.close();
}
return flights;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}