Here are the examples of the java api org.bson.conversions.Bson taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
516 Examples
19
Source : MongoPersistentStoreProvider.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Override
public void start() throws IOException {
MongoClientURI clientURI = new MongoClientURI(mongoURL);
client = new MongoClient(clientURI);
MongoDatabase db = client.getDatabase(clientURI.getDatabase());
collection = db.getCollection(clientURI.getCollection()).withWriteConcern(WriteConcern.JOURNALED);
Bson index = Indexes.ascending(pKey);
collection.createIndex(index);
}
19
Source : ResourceStatusDetailDAO.java
with Apache License 2.0
from YagelNasManit
with Apache License 2.0
from YagelNasManit
/**
* Fetch time scale statuses for particular resource
* @param environmentName environment that resource belongs to
* @param resourceId resource id to fetch statuses
* @param from start date for statuses fetching
* @param to end date for statuses fetching
* @return
*/
public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) {
List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to);
List<StatusUpdate> updates = new ArrayList<>();
for (Date[] dates : dateFrames) {
switchCollection(dates[0]);
Bson filter = and(eq("environmentName", environmentName), eq("resource.resourceId", resourceId), gte("updated", dates[0]), lte("updated", dates[1]));
Bson project = fields(include("updated", "statusOrdinal"), excludeId());
List<StatusUpdate> monthlyUpdates = this.thisCollection.find(filter).projection(project).map(doc -> new StatusUpdateImpl(Status.fromSerialNumber(doc.getInteger("statusOrdinal")), doc.getDate("updated"))).into(new ArrayList<>());
updates.addAll(monthlyUpdates);
}
return updates;
}
19
Source : ResourceLastStatusDAO.java
with Apache License 2.0
from YagelNasManit
with Apache License 2.0
from YagelNasManit
/**
* Get last statuses for particular environment and defined resources
* @param environmentName environment to fetch statuses for
* @param resourceIds resources to fetch statuses for
* @return
*/
public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) {
Bson query = and(eq("environmentName", environmentName), in("resource.resourceId", resourceIds));
List<ResourceStatus> resources = thisCollection.find(query).map(DoreplacedentMapper::resourceStatusFromDoreplacedent).into(new ArrayList<>());
return resources;
}
19
Source : Mongo.java
with Apache License 2.0
from xiancloud
with Apache License 2.0
from xiancloud
public static <T> Page<T> findPageBySkip(MongoCollection<T> collection, Bson filter, long skip, long limit) {
long total = collection.countDoreplacedents(filter);
Page<T> page = new Page<>();
page.setPageSize(new Long(limit).intValue());
page.setTotalPage(Long.valueOf(total / limit).intValue());
page.setPageNumber(Long.valueOf(skip / limit + 1).intValue());
page.setTotal(total);
collection.find(filter).forEach((Consumer<T>) page.getList()::add);
return page;
}
19
Source : Mongo.java
with Apache License 2.0
from xiancloud
with Apache License 2.0
from xiancloud
public static <T> Page<T> findPageByPageNumber(MongoCollection<T> collection, Bson filter, Bson sort, int pageNumber, int pageSize) {
long total = collection.countDoreplacedents(filter);
Page<T> page = new Page<>();
page.setPageSize(pageSize);
int totalPage = new Double(Math.ceil((double) total / pageSize)).intValue();
page.setTotalPage(totalPage);
if (totalPage < pageNumber && totalPage != 0) {
pageNumber = totalPage;
}
page.setPageNumber(pageNumber);
page.setTotal(total);
int skip = (pageNumber - 1) * pageSize;
collection.find(filter).sort(sort).skip(skip).limit(pageSize).forEach((Consumer<T>) page.getList()::add);
return page;
}
19
Source : Mongo.java
with Apache License 2.0
from xiancloud
with Apache License 2.0
from xiancloud
public static <T> Page<T> findPageBySkip(MongoCollection<T> collection, Bson filter, Bson sort, long skip, long limit) {
long total = collection.countDoreplacedents(filter);
Page<T> page = new Page<>();
page.setPageSize(new Long(limit).intValue());
page.setTotalPage(Long.valueOf(total / limit).intValue());
page.setPageNumber(Long.valueOf(skip / limit + 1).intValue());
page.setTotal(total);
collection.find(filter).sort(sort).forEach((Consumer<T>) page.getList()::add);
return page;
}
19
Source : Mongo.java
with Apache License 2.0
from xiancloud
with Apache License 2.0
from xiancloud
public static <T> Page<T> findPageByPageNumber(MongoCollection<T> collection, Bson filter, int pageNumber, int pageSize) {
long total = collection.countDoreplacedents(filter);
Page<T> page = new Page<>();
page.setPageSize(pageSize);
int totalPage = new Double(Math.ceil((double) total / pageSize)).intValue();
page.setTotalPage(totalPage);
if (totalPage < pageNumber && totalPage != 0) {
pageNumber = totalPage;
}
page.setPageNumber(pageNumber);
page.setTotal(total);
int skip = (pageNumber - 1) * pageSize;
collection.find(filter).skip(skip).limit(pageSize).forEach((Consumer<T>) page.getList()::add);
return page;
}
19
Source : MongoCommandTests.java
with Apache License 2.0
from vividus-framework
with Apache License 2.0
from vividus-framework
@ExtendWith(MockitoExtension.clreplaced)
clreplaced MongoCommandTests {
@Mock
private Bson bson;
@Mock
private FindIterable<Doreplacedent> findIterable;
@SuppressWarnings("unchecked")
@Test
void testFind() {
MongoCollection<Doreplacedent> mongoCollection = mock(MongoCollection.clreplaced);
when(mongoCollection.find(bson)).thenReturn(findIterable);
Object output = MongoCommand.FIND.apply(Function.idenreplacedy(), bson).apply(mongoCollection);
replacedertEquals(findIterable, output);
}
@SuppressWarnings("unchecked")
@Test
void testProjection() {
FindIterable<Doreplacedent> projectionIterable = mock(FindIterable.clreplaced);
when(findIterable.projection(bson)).thenReturn(projectionIterable);
Object output = MongoCommand.PROJECTION.apply(Function.idenreplacedy(), bson).apply(findIterable);
replacedertEquals(projectionIterable, output);
}
@Test
void testCollect() {
Doreplacedent doreplacedent = mock(Doreplacedent.clreplaced);
when(findIterable.spliterator()).thenReturn(List.of(doreplacedent).spliterator());
Object output = MongoCommand.COLLECT.apply(Function.idenreplacedy(), bson).apply(findIterable);
replacedertEquals(List.of(doreplacedent), output);
}
@Test
void testCount() {
Doreplacedent doreplacedent = mock(Doreplacedent.clreplaced);
when(findIterable.spliterator()).thenReturn(List.of(doreplacedent).spliterator());
Object output = MongoCommand.COUNT.apply(Function.idenreplacedy(), bson).apply(findIterable);
replacedertEquals(1L, output);
}
}
19
Source : MongoCommandEntry.java
with Apache License 2.0
from vividus-framework
with Apache License 2.0
from vividus-framework
@AsParameters
public clreplaced MongoCommandEntry {
private MongoCommand command;
private Bson argument;
public MongoCommand getCommand() {
return command;
}
public void setCommand(MongoCommand command) {
this.command = command;
}
public Bson getArgument() {
return argument;
}
public void setArgument(Bson argument) {
this.argument = argument;
}
}
19
Source : MongoCommandEntry.java
with Apache License 2.0
from vividus-framework
with Apache License 2.0
from vividus-framework
public void setArgument(Bson argument) {
this.argument = argument;
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getGuildByIdAndUpdate(long guildId, Bson filters, Bson update, FindOneAndUpdateOptions findOneAndUpdateOptions) {
Bson filter;
if (filters != null) {
filter = Filters.and(filters, Filters.eq("_id", guildId));
} else {
filter = Filters.eq("_id", guildId);
}
return this.guilds.findOneAndUpdate(filter, update, findOneAndUpdateOptions == null ? this.defaultFindOneAndUpdateOptions : findOneAndUpdateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateResubscriptionById(String id, Bson update) {
return this.resubscriptions.updateOne(Filters.eq("_id", id), update, this.defaultUpdateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateGuildById(long guildId, Bson filters, Bson update, UpdateOptions updateOptions) {
Bson filter;
if (filters != null) {
filter = Filters.and(Filters.eq("_id", guildId), filters);
} else {
filter = Filters.eq("_id", guildId);
}
return this.updateGuildById(filter, update, updateOptions == null ? this.defaultUpdateOptions : updateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateGuildById(Bson filters, Bson update, UpdateOptions updateOptions) {
return this.guilds.updateOne(filters, update, updateOptions == null ? this.defaultUpdateOptions : updateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getGuildById(long guildId, Bson filters, Bson projection) {
Doreplacedent doreplacedent;
if (filters != null) {
doreplacedent = this.guilds.find(Filters.and(Filters.eq("_id", guildId), filters)).projection(projection).first();
} else {
doreplacedent = this.guilds.find(Filters.eq("_id", guildId)).projection(projection).first();
}
return doreplacedent == null ? Database.EMPTY_DOreplacedENT : doreplacedent;
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void getUserByIdAndUpdate(long userId, Bson update, Bson projection, DatabaseCallback<Doreplacedent> callback) {
this.getUserByIdAndUpdate(userId, null, update, this.defaultFindOneAndUpdateOptions.projection(projection), callback);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateManyUsers(Bson update, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateManyUsers(update), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateManyGuilds(Bson filter, Bson update) {
return this.guilds.updateMany(filter, update);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateManyGuilds(Bson update, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateManyGuilds(update), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void deleteResubscription(Bson filter, DatabaseCallback<DeleteResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.deleteResubscription(filter), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateManyUsers(Bson filter, Bson update) {
return this.users.updateMany(filter, update);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateManyGuilds(Bson update) {
return this.updateManyGuilds(Database.EMPTY_DOreplacedENT, update);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateManyUsers(Bson update) {
return this.updateManyUsers(Database.EMPTY_DOreplacedENT, update);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateManyGuilds(Bson filter, Bson update, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateManyGuilds(filter, update), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void deleteModLogCases(Bson filter, DatabaseCallback<DeleteResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.modLogs.deleteMany(filter), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getUserByIdAndUpdate(long userId, Bson filters, Bson update, FindOneAndUpdateOptions findOneAndUpdateOptions) {
Bson filter;
if (filters != null) {
filter = Filters.and(filters, Filters.eq("_id", userId));
} else {
filter = Filters.eq("_id", userId);
}
return this.users.findOneAndUpdate(filter, update, findOneAndUpdateOptions == null ? this.defaultFindOneAndUpdateOptions : findOneAndUpdateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateGuildById(long guildId, Bson filters, Bson update, UpdateOptions updateOptions, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateGuildById(guildId, filters, update, updateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public DeleteResult deleteResubscription(Bson filter) {
return this.resubscriptions.deleteOne(filter);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateManyUsers(Bson filter, Bson update, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateManyUsers(filter, update), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateUserById(long userId, Bson filters, Bson update, UpdateOptions updateOptions) {
Bson filter;
if (filters != null) {
filter = Filters.and(Filters.eq("_id", userId), filters);
} else {
filter = Filters.eq("_id", userId);
}
return this.updateUserById(filter, update, updateOptions == null ? this.defaultUpdateOptions : updateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void getUserByIdAndUpdate(long userId, Bson filters, Bson update, FindOneAndUpdateOptions findOneAndUpdateOptions, DatabaseCallback<Doreplacedent> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.getUserByIdAndUpdate(userId, filters, update, findOneAndUpdateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getNotification(Bson filter, Bson projection) {
Doreplacedent data = this.getNotifications(filter, projection).first();
return data == null ? Database.EMPTY_DOreplacedENT : data;
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateGuildById(long guildId, Bson update) {
return this.updateGuildById(guildId, null, update, null);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getUserById(long userId, Bson filters, Bson projection) {
Doreplacedent doreplacedent;
if (filters != null) {
doreplacedent = this.users.find(Filters.and(Filters.eq("_id", userId), filters)).projection(projection).first();
} else {
doreplacedent = this.users.find(Filters.eq("_id", userId)).projection(projection).first();
}
return doreplacedent == null ? Database.EMPTY_DOreplacedENT : doreplacedent;
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public FindIterable<Doreplacedent> getGuilds(Bson filter, Bson projection) {
return this.guilds.find(filter).projection(projection);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public FindIterable<Doreplacedent> getNotifications(Bson filter, Bson projection) {
return this.notifications.find(filter).projection(projection).sort(Sorts.descending("timestamp"));
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateUserById(long userId, Bson filters, Bson update, UpdateOptions updateOptions, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateUserById(userId, filters, update, updateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateGuildById(Bson filters, Bson update, UpdateOptions updateOptions, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateGuildById(filters, update, updateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateUserById(Bson filters, Bson update, UpdateOptions updateOptions) {
return this.users.updateOne(filters, update, updateOptions == null ? this.defaultUpdateOptions : updateOptions);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getGuildByIdAndUpdate(long guildId, Bson update, Bson projection) {
return this.getGuildByIdAndUpdate(guildId, null, update, this.defaultFindOneAndUpdateOptions.projection(projection));
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public Doreplacedent getUserByIdAndUpdate(long userId, Bson update, Bson projection) {
return this.getUserByIdAndUpdate(userId, null, update, this.defaultFindOneAndUpdateOptions.projection(projection));
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateResubscriptionById(String id, Bson update, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateResubscriptionById(id, update), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void getGuildByIdAndUpdate(long guildId, Bson filters, Bson update, FindOneAndUpdateOptions findOneAndUpdateOptions, DatabaseCallback<Doreplacedent> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.getGuildByIdAndUpdate(guildId, filters, update, findOneAndUpdateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public UpdateResult updateUserById(long userId, Bson update) {
return this.updateUserById(userId, null, update, null);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateUserById(Bson filters, Bson update, UpdateOptions updateOptions, DatabaseCallback<UpdateResult> callback) {
this.queryExecutor.submit(() -> {
try {
callback.onResult(this.updateUserById(filters, update, updateOptions), null);
} catch (Throwable e) {
callback.onResult(null, e);
}
});
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateUserById(long userId, Bson update, DatabaseCallback<UpdateResult> callback) {
this.updateUserById(userId, null, update, null, callback);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void updateGuildById(long guildId, Bson update, DatabaseCallback<UpdateResult> callback) {
this.updateGuildById(guildId, null, update, null, callback);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public void getGuildByIdAndUpdate(long guildId, Bson update, Bson projection, DatabaseCallback<Doreplacedent> callback) {
this.getGuildByIdAndUpdate(guildId, null, update, this.defaultFindOneAndUpdateOptions.projection(projection), callback);
}
19
Source : Database.java
with MIT License
from sx4-discord-bot
with MIT License
from sx4-discord-bot
public int getGuildsGained(Bson filter) {
FindIterable<Doreplacedent> guildLogs = this.guildLogs.find(filter).projection(Projections.include("joined"));
int guildsGained = 0;
for (Doreplacedent guildLog : guildLogs) {
boolean joined = guildLog.getBoolean("joined");
if (joined) {
guildsGained++;
} else {
guildsGained--;
}
}
return guildsGained;
}
19
Source : MongoDBClient.java
with MIT License
from sun0x00
with MIT License
from sun0x00
/**
* 通过_id删除数据
*
* @param dbName
* @param collectionName
* @param _id
* @return
*/
public boolean deleteById(String dbName, String collectionName, String _id) {
ObjectId objectId = new ObjectId(_id);
Bson filter = Filters.eq("_id", objectId);
DeleteResult deleteResult = getDatabase(dbName).getCollection(collectionName).deleteOne(filter);
long deletedCount = deleteResult.getDeletedCount();
return deletedCount > 0 ? true : false;
}
See More Examples