Questions tagged [mongo-java-driver]

The Java driver for MongoDB

The MongoDB Java Driver.

Using the Java driver is very simple. First, be sure to include the driver jar mongo.jar in your classpath.

The following code snippets come from the QuickTour.java example code that can be found with the driver source.

347 questions
0
votes
0 answers

How to get last array element while Projection mongodb

I have following document structure (This is dummy document for understanding purpose) { "id" : "p1245", "Info" : [ { "cloth_name" : "ABC", "cloth_type" : "C" }, { …
PKH
  • 47
  • 1
  • 2
  • 6
0
votes
2 answers

How to add and remove users in MongoDB Java Driver 2.13?

Using terminal, I can add user using db.createUser(user, writeConcern)and remove it using db.dropUser(username, writeConcern) How to add and remove users in MongoDB Java Driver 2.13?
Dev
  • 13,492
  • 19
  • 81
  • 174
0
votes
0 answers

Mismatch of Date format in mongoDB on migration

I am migrating from MySQL to NoSql.Using mongo java driver I am able to insert the date fields which are currently being stored as NumberLong("1212121").However when I migrated the data from MySQL to NoSQL using Mongify the date field are getting…
Amar
  • 955
  • 3
  • 11
  • 28
0
votes
1 answer

How to get data as byte[] using GridFS Java API?

I am using Java-driver 2.13. GridFS takes input as File, InputStream or byte[] in createFile() method on GridFS instance to create GridFSInputFile . But when I tried to fetch data back I do have option only as File or outputStream using…
Dev
  • 13,492
  • 19
  • 81
  • 174
0
votes
1 answer

Bulk upsert using MongoDb BulkWriteOperation throwing IllegalArgumentException

I'm trying to do a bulk upsert using BulkWriteOperation. public BulkWriteResult bulkUpsert(DomainName domainName, Map dbObjectByQueryMap) { BulkWriteOperation bulkWriteOperation =…
Krishna Gollapudi
  • 1,609
  • 16
  • 13
0
votes
1 answer

Mongo Data not expiring

I'm trying to insert a record in mongo that expires in sometime. getMessagesCollection().ensureIndex(new BasicDBObject("createdAt", 1), new BasicDBObject("expireAfterSeconds", 10)); I insert my data like this Map map = new HashMap(); map.put("_id",…
KS88
  • 147
  • 1
  • 1
  • 8
0
votes
2 answers

why does the mongo-java-driver DBCollection.aggregate() return NoSuchMethod

Here is part of a stack trace I am getting when I call the aggregate method on mongodb's DBCollection object: java.lang.NoSuchMethodError: com.mongodb.DBCollection.aggregate(Ljava/util/List;)Lcom/mongodb/AggregationOutput; at…
Alex Ryan
  • 3,719
  • 5
  • 25
  • 41
0
votes
1 answer

How do you execute java queries based on ObjectID.timestamp?

How do you query time based queries from the ObjectID.timestamp()? db.myCollectin.findOne()._id.getTimestamp() I've tried Date date = new Date(); BasicDBObject query = new BasicDBObject("timestamp", new BasicDBObject("$lt",…
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
-1
votes
1 answer

Getting issue Upgrading from Mongo driver version 3.8.1 to 4.6.1

After updating the mongo driver version from 3.8.1 to 4.6.1. I am getting below error in my existing queries "Unrecognized pipeline stage name: '$and'" All the aggregations were working Earlier. Spring boot version - 2.7.10 Java version - 11 If I…
HMT
  • 2,093
  • 1
  • 19
  • 51
-1
votes
1 answer

Retrieve fields of all documents in mongodb collection

I am trying to retrieve all Fields of all Documents and embeded Documents in Mongo collection. this is an example of one document: { "_id": { "$oid": "53b309def468718462e0c390" }, "customer": { "companyName": "Vins et alcools…
-1
votes
1 answer

JSON parsing fails for string but passes for number in Java

I am writing a parser for incoming JSON data with no definite structure for the values within the JSON. For example a given key within the parent JSON can have an integer or a string value. In some cases it can also be another JSON string. When…
Navin Nagpal
  • 640
  • 10
  • 25
-1
votes
1 answer

Casting BasicDBList to Java Arraylist

I am having a difficulty. I have retrieved a BasicDBList from database but now I want to iterate over the list but I cannot do it in it's BasicDBList format. So I want to ask that how can we cast BasicDBList to ArrayList of Java. Here is what I have…
Muhammad Rafique
  • 157
  • 2
  • 15
-1
votes
1 answer

Error 11000 in Mongo Java, DuplicateKeyException

I have a piece of code, as following and have been getting this error in Java. coll is the collection where I need to insert data. I was hoping mongodb would automatically generate the ids so putting the same data (in a for loop) wouldn't matter but…
-1
votes
1 answer

Not able to get the aggregate result in mongo embedded document by querying

Issue in querying the embedded document in mongo db. I am trying to get the conversationId for the users but it returning null. Sample document: { "_id" : ObjectId("5787391f191fda3a4430c749"), "conversationId" : "fWFGIr0xAbQytmVcQIPV", "user" :…
-1
votes
1 answer

MongoDb database connection using java and authentication with 3.0.0 version

I have MongoConnectionUtils this file I have dependecy below mongo-java-driver org.mongodb mongo-java-driver 3.0.0 public class…
Kamini
  • 690
  • 2
  • 13
  • 36
1 2 3
23
24