List of usage examples for com.mongodb.client.model Filters eq
public static <TItem> Bson eq(final String fieldName, @Nullable final TItem value)
From source file:be.nille.blog.mongo.author.MongoAuthorService.java
@Override public Author findById(String authorId) { FindIterable<Document> iterable = collection.find(Filters.eq("_id", new ObjectId(authorId))); Document first = iterable.first(); if (first != null) { return new Author(new MAuthorAccess(first)); }/*from w w w . j a v a 2 s . c o m*/ throw new MongoServiceException(String.format("Could not find author with id %s", authorId)); }
From source file:be.nille.blog.mongo.author.MongoAuthorService.java
@Override public Author save(Author author) { Document document = new AuthorDocument(author).toDocument(); if (author.getId() == null) { collection.insertOne(document);//from w w w . j a v a 2s . c o m return new Author(new MAuthorAccess(document)); } Bson filter = Filters.eq("_id", new ObjectId(author.getId())); collection.replaceOne(filter, document); return author; }
From source file:be.nille.blog.mongo.category.MongoCategoryService.java
@Override public Category findById(String categoryId) { FindIterable<Document> iterable = collection.find(Filters.eq("_id", new ObjectId(categoryId))); Document first = iterable.first(); if (first != null) { return new Category(new MCategoryAccess(first)); }/*w w w .j a va 2s . c o m*/ throw new MongoServiceException(String.format("Could not find category with id %s", categoryId)); }
From source file:be.nille.blog.mongo.category.MongoCategoryService.java
@Override public Category save(Category category) { Document document = new CategoryDocument(category).toDocument(); if (category.getId() == null) { collection.insertOne(document);/* ww w . j a va2s . c o m*/ return new Category(new MCategoryAccess(document)); } Bson filter = Filters.eq("_id", new ObjectId(category.getId())); collection.replaceOne(filter, document); return category; }
From source file:be.nille.blog.mongo.post.MongoPostService.java
@Override public List<Post> findPostsByCategory(String categoryId) { Bson filter = Filters.eq("category", new ObjectId(categoryId)); return getPostsByIterable(collection.find(filter)); }
From source file:be.nille.blog.mongo.post.MongoPostService.java
@Override public Post findPostById(String postId) { FindIterable<Document> iterable = collection.find(Filters.eq("_id", new ObjectId(postId))); Document first = iterable.first(); if (first != null) { return new Post(new MPostAccess(first, database)); }/*w ww .ja va 2s .c o m*/ throw new MongoServiceException(String.format("Could not find post with id %s", postId)); }
From source file:be.nille.blog.mongo.post.MongoPostService.java
@Override public Post save(Post post) { Document document = new PostDocumentFactory().create(post); if (post.getId() == null) { collection.insertOne(document);//ww w . j a v a 2 s . co m return new Post(new MPostAccess(document, database)); } Bson filter = Filters.eq("_id", new ObjectId(post.getId())); collection.replaceOne(filter, document); return post; }
From source file:be.nille.blog.mongo.post.MPostAccess.java
@Override public Author getAuthor() { MongoCollection authorCollection = database.getCollection("author"); ObjectId authorObjectId = (ObjectId) document.get("author"); FindIterable<Document> iterable = authorCollection.find(Filters.eq("_id", authorObjectId)); Document first = iterable.first(); if (first != null) { return new Author(new MAuthorAccess(first)); }/*from w ww. j a v a 2 s . c om*/ return null; }
From source file:be.nille.blog.mongo.post.MPostAccess.java
@Override public Category getCategory() { MongoCollection categoryCollection = database.getCollection("category"); ObjectId categoryObjectId = (ObjectId) document.get("category"); FindIterable<Document> iterable = categoryCollection.find(Filters.eq("_id", categoryObjectId)); Document first = iterable.first(); if (first != null) { return new Category(new MCategoryAccess(first)); }// w ww .j ava 2 s . c om return null; }
From source file:br.edu.ifpb.bdnc.daos.PaginaDao.java
@Override public List<Pagina> search(String titulo) { Bson filter = Filters.or(Filters.eq("titulo", titulo), Filters.eq("listPalavras.palavraChave", titulo), Filters.eq("listCateg.categoria", titulo)); list = new ArrayList<>(); col = conn.openConnection();/*w w w .jav a 2 s . c o m*/ cursor = col.find(filter).iterator(); System.out.println("antes do while"); while (cursor.hasNext()) { System.out.println("depois do while"); pagina = new Pagina().fromDocument(cursor.next()); list.add(pagina); conn.close(); } return list; }