mongodb-java

Spring Data-MongoDb Options for aggregation method

北慕城南 提交于 2019-12-20 03:29:44
问题 How can i set " allowDiskUse " option in aggregation method in spring data-mongodb framework ? 回答1: The core aggregation abstraction in Spring Data MongoDB is - as the name suggests - Aggregation . It exposes a fluent API to build up a pipeline using aggregation operations. As of version 1.6.0.M1 the Aggregation class has a ….withOptions(…) method to be used like this: Aggregation aggregation = newAggregation(…) // build up pipeline in here .withOptions(newAggregationOptions().allowDiskUse

Finding distinct from collections in mongodb

社会主义新天地 提交于 2019-12-20 02:35:19
问题 Our previous implementation for finding distinct elements from a collection used to be : List<String> names = mongoClient.getDB(dbName).getCollection(collectionName).distinct(NAME_KEY); Trying to upgrade this into the current implementation with mongo 3.3.0+ as tried is : List<String> names = mongoClient.getDatabase(dbName) .getCollection(collectionName, TDocType.class) .distinct(NAME_KEY, String.class); // compile error - required Class<TResult> Have also given a try to .distinct(NAME_KEY,

Sort documents in collections while fetching

泄露秘密 提交于 2019-12-20 02:29:16
问题 I have a collection called at MongoDB called resource. It has the following documents: { "_id" : "Abb.e", "_class" : "Resource", "resourceEmail" : "test1@test.com" } { "_id" : "Dasd.tt", "_class" : "Resource","resourceEmail" : "test2@test.com" } { "_id" : "Bbb.rr", "_class" : "Resource", "resourceEmail" : "test3@test.com" } At Java code,I list them as follows: MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate(); List<Resource> resourceList = mongoOperations.findAll

Spring Data MongoDB 4.0 transactions support

旧巷老猫 提交于 2019-12-19 11:49:15
问题 MongoDB 4.0 are going to introduce transactions support with ACID guarantees. Does Spring Data MongoDB already supports the transactions in MongoDB and if no, when this awesome feature will be available. I really need it, taking into account the following issue - MongoDB schema design in order to support application horizontal scaling 回答1: Does Spring Data MongoDB already supports the transactions in MongoDB Spring Data Lovelace M3 (2.1.0.M3) supports synchronous transaction for MongoDB v4.0,

Mongodb database Schema Design with shared data

孤者浪人 提交于 2019-12-19 10:33:32
问题 Hi I am newbie to mongodb.I am using java. I have 4 tables Tenant,system,authorization in my relational table. Something like this. Table Fields Tenant Tenant_ID(PK), Tenant_INFO System System_ID(PK), System_Info Authorization System_ID, Autho_Info. System_prop System_ID, Prop_Info, Tenant_ID In System_prop table, Tenant_ID refers the Tenant Table Tenant_ID (PK), System_ID refers the System Table System_ID. In Authorization table, System_ID refers System tabel System_ID I am switching my

POJO to org.bson.Document and Vice Versa

寵の児 提交于 2019-12-19 05:23:55
问题 Is there a simple way to convert Simple POJO to org.bson.Document? I'm aware that there are ways to do this like this one: Document doc = new Document(); doc.append("name", person.getName()): But does it have a much simpler and typo less way? 回答1: The point is, that you do not need to put your hands on org.bson.Document. Morphia will do all that for you behind the curtain. import com.mongodb.MongoClient; import org.mongodb.morphia.Datastore; import org.mongodb.morphia.DatastoreImpl; import

Mongodb: `com.mongodb.MongoSocketReadException: Prematurely reached end of stream` with morphia

不打扰是莪最后的温柔 提交于 2019-12-18 15:43:29
问题 I've a simple data structure (the Transaction referenced below) to be inserted into mongodb: {"amount":111,"debitAcc":"588188286231743e7d5c923d","type":"CHARGE"} An I got the following error stack: com.mongodb.MongoSocketReadException: Prematurely reached end of stream at com.mongodb.connection.SocketStream.read(SocketStream.java:88) at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494) at com.mongodb.connection.InternalStreamConnection

Searching a value in a specific field in MongoDB Full Text Search

别来无恙 提交于 2019-12-18 05:57:34
问题 (MongoDB Full Text Search) Hello, I have put some fields in index and this is how I could search for a search_keyword . BasicDBObject search = new BasicDBObject("$search", "search_keyword"); BasicDBObject textSearch = new BasicDBObject("$text", search); DBCursor cursor = users.find(textSearch); I don't want search_keyword to be searched in all the fields specified in the index. *Is there any method to specify search_keyword to be searched in specific fields from the index??* If so, please

MongoDb connection refused

两盒软妹~` 提交于 2019-12-18 03:12:25
问题 This is my first attempt to consume MongoDB. I've got Mongo running: ps -ef | grep [m]ongo mongodb 11023 1 0 Jun24 ? 00:00:03 /usr/lib/mongodb/mongod --config /etc/mongodb.conf And the error comes as the result of doing Datastore.save( stuff ); // (pseudo code) The error: Jun 27, 2011 3:20:29 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize WARNING: Exception determining maxBSON size using0 java.io.IOException: couldn't connect to [russ-elite-book/127.0.1.1:27017] bc:java.net

MongoDb connection refused

穿精又带淫゛_ 提交于 2019-12-18 03:12:03
问题 This is my first attempt to consume MongoDB. I've got Mongo running: ps -ef | grep [m]ongo mongodb 11023 1 0 Jun24 ? 00:00:03 /usr/lib/mongodb/mongod --config /etc/mongodb.conf And the error comes as the result of doing Datastore.save( stuff ); // (pseudo code) The error: Jun 27, 2011 3:20:29 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize WARNING: Exception determining maxBSON size using0 java.io.IOException: couldn't connect to [russ-elite-book/127.0.1.1:27017] bc:java.net