org.bson.BsonElement Java Examples
The following examples show how to use
org.bson.BsonElement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateDescription.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
/** * Convert this update description to an update document. * * @return an update document with the appropriate $set and $unset documents. */ public BsonDocument toUpdateDocument() { final List<BsonElement> unsets = new ArrayList<>(); for (final String removedField : this.removedFields) { unsets.add(new BsonElement(removedField, new BsonBoolean(true))); } final BsonDocument updateDocument = new BsonDocument(); if (this.updatedFields.size() > 0) { updateDocument.append("$set", this.updatedFields); } if (unsets.size() > 0) { updateDocument.append("$unset", new BsonDocument(unsets)); } return updateDocument; }
Example #2
Source File: BsonRecordSerialiser.java From octarine with Apache License 2.0 | 5 votes |
@Override public BsonDocument applyUnsafe(Record record) throws IOException { List<BsonElement> elems = serialiserMap.entrySet().stream() .filter(e -> e.getKey().get(record).isPresent()) .map(e -> ((Function<Object, BsonElement>) serialiserMap.get(e.getKey())).apply(e.getKey().get(record).get())) .collect(Collectors.toList()); return new BsonDocument(elems); }
Example #3
Source File: TraceMongoCommandListenerTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void getCollectionName_allowListedCommandAndCollectionField() { BsonDocument command = new BsonDocument(Arrays.asList( new BsonElement("collection", new BsonString("coll")), new BsonElement("find", new BsonString("bar")) )); assertThat(listener.getCollectionName(command, "find")).isEqualTo("bar"); // command wins }
Example #4
Source File: TraceMongoCommandListenerTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void getCollectionName_notAllowListedCommandAndCollectionField() { BsonDocument command = new BsonDocument(Arrays.asList( new BsonElement("collection", new BsonString("coll")), new BsonElement("cmd", new BsonString("bar")) )); assertThat(listener.getCollectionName(command, "cmd")).isEqualTo( "coll"); // collection field wins }
Example #5
Source File: BsonRecordSerialiser.java From octarine with Apache License 2.0 | 4 votes |
public <V> Builder write(Key<? extends V> key, String fieldName, Function<? super V, BsonValue> serialiser) { Function<? extends V, BsonElement> keyValueWriter = (V value) -> new BsonElement(fieldName, serialiser.apply(value)); serialiserMap.put(key, keyValueWriter); return this; }
Example #6
Source File: BsonRecordSerialiser.java From octarine with Apache License 2.0 | 4 votes |
public BsonRecordSerialiser(Map<Key<?>, Function<?, BsonElement>> serialiserMap) { this.serialiserMap = serialiserMap; }