default Document convertJson(String query) { return Document.parse(query); } WriteConcern getWriteConcern(final ConfigurationContext context);
public BasicUpdate(String updateString) { super(); this.updateObject = Document.parse(updateString); }
/** * Create a new {@link BasicQuery} given a JSON {@code query} and {@code fields}. * * @param query may be {@literal null}. * @param fields may be {@literal null}. */ public BasicQuery(@Nullable String query, @Nullable String fields) { this(query != null ? Document.parse(query) : new Document(), fields != null ? Document.parse(fields) : new Document()); }
public static Constraints.ConstraintHost jsonQuery(String query) { return new JsonQuery(Document.parse(query)); }
private static Document parse(String source) { try { return Document.parse(source); } catch (JSONParseException | org.bson.json.JsonParseException o_O) { throw new MappingException("Could not parse given String to save into a JSON document!", o_O); } }
/** * Parses a string in MongoDB Extended JSON format to a {@code Document} * * @param json the JSON string * @return a corresponding {@code Document} object * @see org.bson.json.JsonReader * @mongodb.driver.manual reference/mongodb-extended-json/ MongoDB Extended JSON */ public static Document parse(final String json) { return parse(json, new DocumentCodec()); }
public Document doInDB(MongoDatabase db) throws MongoException, DataAccessException { return db.runCommand(Document.parse(jsonCommand), Document.class); } });
public Mono<Document> executeCommand(String jsonCommand) { Assert.notNull(jsonCommand, "Command must not be empty!"); return executeCommand(Document.parse(jsonCommand)); }
private org.bson.Document resolveCompoundIndexKeyFromStringDefinition(String dotPath, String keyDefinitionString) { if (!StringUtils.hasText(dotPath) && !StringUtils.hasText(keyDefinitionString)) { throw new InvalidDataAccessApiUsageException("Cannot create index on root level for empty keys."); } if (!StringUtils.hasText(keyDefinitionString)) { return new org.bson.Document(dotPath, 1); } org.bson.Document dbo = org.bson.Document.parse(keyDefinitionString); if (!StringUtils.hasText(dotPath)) { return dbo; } org.bson.Document document = new org.bson.Document(); for (String key : dbo.keySet()) { document.put(dotPath + "." + key, dbo.get(key)); } return document; }
public IndexOptionsBuilder(final IndexOptions original, final String prefix) { super(original); if(!"".equals(original.partialFilter())) { final Document parse = Document.parse(original.partialFilter()); final Document filter = new Document(); for (final Entry<String, Object> entry : parse.entrySet()) { filter.put(prefix + "." + entry.getKey(), entry.getValue()); } partialFilter(filter.toJson()); } }
/** * Add a default sort derived from {@link org.springframework.data.mongodb.repository.Query#sort()} to the given * {@link Query} if present. * * @param query the {@link Query} to potentially apply the sort to. * @return the query with potential default sort applied. * @since 2.1 */ Query applyAnnotatedDefaultSortIfPresent(Query query) { if (!method.hasAnnotatedSort()) { return query; } return QueryUtils.decorateSort(query, Document.parse(method.getAnnotatedSort())); }
/** * Add a default sort derived from {@link org.springframework.data.mongodb.repository.Query#sort()} to the given * {@link Query} if present. * * @param query the {@link Query} to potentially apply the sort to. * @return the query with potential default sort applied. * @since 2.1 */ Query applyAnnotatedDefaultSortIfPresent(Query query) { if (!method.hasAnnotatedSort()) { return query; } return QueryUtils.decorateSort(query, Document.parse(method.getAnnotatedSort())); }
@Test public void jsonObjects() { getMorphia().map(JsonList.class); populate(new BasicDBObject(Document.parse("{\"jsonObject\": { \"array\": [{ \"foo\": \"bar\" }]},}"))); populate(new BasicDBObject(Document.parse("{\"jsonList\" : [ 1, \"string\", true, null ],}"))); populate(new BasicDBObject(Document.parse("{\"jsonList\" : [ { \"foo\" : \"bar\" }],}"))); }
private Consumer<MongoClient> createInsertItemDefault(int id) { return client -> client.getDatabase(DB_NAME).getCollection(this.getCollectionName()) .insertOne(Document.parse("{" + "'_id': " + id + "," + "'dataStr': 'hello'," + "'dataInt': 123," + "'dataLong': 80000000000," + "'dataBoolean': true," + "'dataByte': -1," + "'dataArrayOfStr': ['a','c','e']," + "'nested': {" + "'dataStr': 'hello'," + "'dataInt': 123," + "'dataLong': 80000000000," + "'dataBoolean': true," + "'dataByte': -1" + "}}") ); }
@Test public void validationDocuments() { Document validator = Document.parse("{ \"jelly\" : { \"$ne\" : \"rhubarb\" } }"); getMorphia().map(DocumentValidation.class); MappedClass mappedClass = getMorphia().getMapper().getMappedClass(DocumentValidation.class); for (ValidationLevel level : EnumSet.allOf(ValidationLevel.class)) { for (ValidationAction action : EnumSet.allOf(ValidationAction.class)) { checkValidation(validator, mappedClass, level, action); } } }
protected List<Document> loadTestDocuments(String pathOnClasspath) { List<Document> results = new ArrayList<>(); try (InputStream stream = Testing.Files.readResourceAsStream(pathOnClasspath);) { assertThat(stream).isNotNull(); IoUtil.readLines(stream, line -> { Document doc = Document.parse(line); assertThat(doc.size()).isGreaterThan(0); results.add(doc); }); } catch (IOException e) { fail("Unable to find or read file '" + pathOnClasspath + "': " + e.getMessage()); } return results; }
@Test public void createValidation() { getMorphia().map(DocumentValidation.class); getDs().enableDocumentValidation(); assertEquals(Document.parse(DocumentValidation.class.getAnnotation(Validation.class).value()), getValidator()); try { getDs().save(new DocumentValidation("John", 1, new Date())); fail("Document should have failed validation"); } catch (WriteConcernException e) { assertTrue(e.getMessage().contains("Document failed validation")); } getDs().save(new DocumentValidation("Harold", 100, new Date())); }
@Test public void saveToNewCollection() { getMorphia().map(DocumentValidation.class); final Document validator = Document.parse("{ \"number\" : { \"$gt\" : 10 } }"); String collection = "newdocs"; addValidation(validator, collection); try { getAds().save(collection, new DocumentValidation("Harold", 8, new Date())); fail("Document validation should have complained"); } catch (WriteConcernException e) { // expected } getAds().save(collection, new DocumentValidation("Harold", 8, new Date()), new InsertOptions() .bypassDocumentValidation(true)); Query<DocumentValidation> query = getAds().createQuery(collection, DocumentValidation.class) .field("number").equal(8); Assert.assertNotNull(query.find(new FindOptions().limit(1)).tryNext()); }
@OnEnabled public void onEnabled(final ConfigurationContext context) { this.lookupValueField = context.getProperty(LOOKUP_VALUE_FIELD).getValue(); this.controllerService = context.getProperty(CONTROLLER_SERVICE).asControllerService(MongoDBClientService.class); this.schemaNameProperty = context.getProperty(SchemaAccessUtils.SCHEMA_NAME).getValue(); this.databaseName = context.getProperty(DATABASE_NAME).evaluateAttributeExpressions().getValue(); this.collection = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions().getValue(); String configuredProjection = context.getProperty(PROJECTION).isSet() ? context.getProperty(PROJECTION).getValue() : null; if (!StringUtils.isBlank(configuredProjection)) { projection = Document.parse(configuredProjection); } super.onEnabled(context); }