mongo-java

Play! 2 Framework - Add Java Mongo driver

泄露秘密 提交于 2019-12-06 11:50:18
问题 I am trying to use the java mongo driver with Play!. So I read though: http://www.playframework.org/documentation/2.0.2/SBTDependencies http://www.mongodb.org/display/DOCS/Java+Tutorial I added the buildpath in eclipse. But play can't find the dependency. So there is an example on the playframework homepage but I still can't figure it out. val appDependencies = Seq( "org.scala-tools" %% "scala-stm" % "0.3", "org.apache.derby" % "derby" % "10.4.1.3" % "test" ) Why are der two% signs? How do I

java code gives error in mongodb while compiling

╄→гoц情女王★ 提交于 2019-12-05 18:25:41
I am new to mongodb and i have the following code import com.mongodb.*; import com.mongodb.Block; import com.mongodb.client.AggregateIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.bson.types.ObjectId; import static java.util.Arrays.asList; public class getAssets{ public static void main( String args[] ){ Block<Document> printBlock = new Block<Document>() { @Override public void apply(final Document document) { System.out.println(document.toJson()); } }; MongoClient mongoClient = new MongoClient("localhost"

Play! 2 Framework - Add Java Mongo driver

左心房为你撑大大i 提交于 2019-12-04 17:02:57
I am trying to use the java mongo driver with Play!. So I read though: http://www.playframework.org/documentation/2.0.2/SBTDependencies http://www.mongodb.org/display/DOCS/Java+Tutorial I added the buildpath in eclipse. But play can't find the dependency. So there is an example on the playframework homepage but I still can't figure it out. val appDependencies = Seq( "org.scala-tools" %% "scala-stm" % "0.3", "org.apache.derby" % "derby" % "10.4.1.3" % "test" ) Why are der two% signs? How do I get the correct names? I only know that the version should be 2.8.0. So if I want to add the Java

MongoDB: how to group by date with mongo date aggregration using java driver

本小妞迷上赌 提交于 2019-12-04 06:32:15
问题 I have been struggling writing to convert a mongo shell command to java query on top of the java mongo driver in order to call it in my webapp project: the command is as follow: db.post.aggregate( { $match: { dateCreated: { "$gt": new ISODate("2013-08-09T05:51:15.000Z"), "$lt": new ISODate("2013-08-09T05:51:20.000Z") } } }, { $group: { _id: { hour: {$hour: "$dateCreated"}, minute: {$minute: "$dateCreated"}, second: {$second: "$dateCreated"} }, cnt: {$sum : 1} } } ) The query above outputs

MongoDB: how to group by date with mongo date aggregration using java driver

独自空忆成欢 提交于 2019-12-02 10:12:10
I have been struggling writing to convert a mongo shell command to java query on top of the java mongo driver in order to call it in my webapp project: the command is as follow: db.post.aggregate( { $match: { dateCreated: { "$gt": new ISODate("2013-08-09T05:51:15.000Z"), "$lt": new ISODate("2013-08-09T05:51:20.000Z") } } }, { $group: { _id: { hour: {$hour: "$dateCreated"}, minute: {$minute: "$dateCreated"}, second: {$second: "$dateCreated"} }, cnt: {$sum : 1} } } ) The query above outputs result in the format below in the mongo shell: { "result" : [ { "_id" : { "hour" : 5, "minute" : 51,

Mongo Connection Pooling(Changing the size of connection pool)

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:50:49
问题 How to change the mongo connection pool size? I have seen it is 100 by default. Is there a way to change this value? I dont want to do it via spring, is there a way to configure it via MongoClient? There is an option i see about mongoClientOptions but i dont see options to set connection pool 回答1: You can build your own MongoClient instance using the MongoClientOptions.Builder. MongoClientOptions.Builder builder = new MongoClientOptions.Builder(); MongoClientOptions options = builder

Mongo Connection Pooling(Changing the size of connection pool)

我只是一个虾纸丫 提交于 2019-12-02 02:39:08
How to change the mongo connection pool size? I have seen it is 100 by default. Is there a way to change this value? I dont want to do it via spring, is there a way to configure it via MongoClient? There is an option i see about mongoClientOptions but i dont see options to set connection pool You can build your own MongoClient instance using the MongoClientOptions.Builder . MongoClientOptions.Builder builder = new MongoClientOptions.Builder(); MongoClientOptions options = builder.connectionsPerHost(10).build(); MongoClient client = new MongoClient(listOfServers, options); As another option(and

How to filter documents based on an embedded array?

人盡茶涼 提交于 2019-12-01 10:47:32
After reviewing this page , specifically this query db.scores.find( { results: { $elemMatch: { $gte: 80, $lt: 85 } } } ) I used the following imports import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.elemMatch; import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Projections.excludeId; import static com.mongodb.client.model.Projections.fields; import static com.mongodb.client.model.Projections.include; And came up with the following code to perform a similar operation ( ARRAY_FIELD_NAME = "myArray" )

MongoDB Java: Finding objects in Mongo using QueryBuilder $in operator returns nothing

霸气de小男生 提交于 2019-12-01 06:53:46
I have a JUnit rule called as MongoRule looks like public class MongoRule extends ExternalResource { private static final Logger LOGGER = LoggerFactory.getLogger(MongoRule.class); private final MongoService mongoService; public MongoRule() throws UnknownHostException { mongoService = new MongoService(getConfiguredHost(), getConfiguredPort(), getConfiguredDatabase()); } @Override protected void before() throws Throwable { LOGGER.info(" Setting up Mongo Database - " + getConfiguredDatabase()); } @Override protected void after() { LOGGER.info("Shutting down the Mongo Database - " +

MongoDB Java: Finding objects in Mongo using QueryBuilder $in operator returns nothing

↘锁芯ラ 提交于 2019-12-01 05:05:55
问题 I have a JUnit rule called as MongoRule looks like public class MongoRule extends ExternalResource { private static final Logger LOGGER = LoggerFactory.getLogger(MongoRule.class); private final MongoService mongoService; public MongoRule() throws UnknownHostException { mongoService = new MongoService(getConfiguredHost(), getConfiguredPort(), getConfiguredDatabase()); } @Override protected void before() throws Throwable { LOGGER.info(" Setting up Mongo Database - " + getConfiguredDatabase());