On Thursday, 28 January 2016 16:23:36 UTC+11, jagvandan nayak wrote:
I am facing issue with Mongo DB document persist.I am able to read all the records from input file but while persisting into Mongo DB, documents are getting skipped. There is no error in logs.For example, there are 100 records in the input file but after staging data into Mongo DB, only 44 records are getting persist.As soon as the size is getting increased in mongo db , the document persistence frequency is getting decreased and after a point around 970 records, not even a single document is getting persisted in mongo db.
Hi Jagvandan,
Can you please provide some further details:
How you are inserting documents into MongoDB (custom code, mongoimport
, etc)
The specific version of the client/driver you are using
A usage example (code or command-line) for how you are inserting documents and checking that they are successfully inserted
Thanks,
Stephen
On Friday, 29 January 2016 21:41:26 UTC+11, jagvandan nayak wrote:
1) In order to insert documents into MongoDB we call the save method of class DBCollection(import com.mongodb.DBCollection) where DBObject
is passed as the argument(import com.mongodb.DBObject).
…
collection.save(object2);
Hi Jagvandan,
Your code snippet isn’t checking the result of the save()
. You should also be aware that the save()
method does upserts if your objects have an _id
field. If your intent is only to insert new documents, you should be using the insert()
method instead. For an import use case, bulk write operations are generally more appropriate.
Are you using the Mongo class or MongoClient (which superceded the Mongo class in the 2.10 driver)? If you are using the older Mongo class and have not set any WriteConcern, the default will be unacknowledged writes.
2) The specific version of the client/driver we are using are
a)mongo-java-driver-2.10.1.jar
b)mongodb_client-1.0.jar
The 2.10 Java driver is very old (Dec 2012) and is not fully compatible with MongoDB 3.x (see: Java Driver Compatibility). For example, it does not include support for the newer bulk write operations API added in MongoDB 2.6.
As a starting point to eliminate driver compatibility problems please upgrade to a newer version of the Java driver. If this is a new project, you should use the latest Java driver (3.x series).
You also mentioned using MongoDB 3.0.4 server. I would strongly encourage upgrading to the latest 3.0.x (currently 3.0.9) as there have been some important bug fixes: Release Notes for MongoDB 3.0.
Regards,
Stephen