mongodb-java-driver-3.4.2 cannot save _id as compound field?

16 views
Skip to first unread message

Need Help

unread,
Jul 21, 2017, 3:52:47 PM7/21/17
to mongodb-user
We used to have _id field as type Document/DBObject/HashMap, such as:
----------------------------------------------------------------------------------
{ "_id" : { "c" : 1, "p" : 897564, "r" : "T", "o" : [ "C" ] } }

However, we have migrated to mongodb 3.4.4 recently, and I can no longer insert Document with compounded _id field in java.  It has created a new _id field, and changed my _id.
------------------------------------------------------------------------------------
This is the document I tried to insert: {"_id":{"c":1,"p":1}}
This is what I got in mongo: { "_id" : ObjectId("59725af7e93d34a706522d6e"), "c" : 1, "p" : 1 }

However, I can still insert the document with correct _id in mongo shell:
-----------------------------------------------------------------------
> db.xxx_1.insert({"_id":{"c":1,"p":1}})
WriteResult({ "nInserted" : 1 })
> db.xxx_1.find()
{ "_id" : { "c" : 1, "p" : 1 } }

Do I need special setup? 

Thanks for your help in advance!



Need Help

unread,
Jul 21, 2017, 7:34:57 PM7/21/17
to mongodb-user
I have found the answer.  Thank you very much!
Reply all
Reply to author
Forward
0 new messages