Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2783

InsertOne/InsertMany/ReplaceOne do not accept a BsonValue parameter like updateOne/updateMany does.

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.6.3
    • API
    • None

    Description

      We started implementing the ORM that came with version 3.x.

      We decorate our Pojos with a custom hash. We now use your ORM to convert the object to BsonDocuments, we then edit it, and then we use it with your MongoCollection.

      I've got it all to work, but i'm disappointed that some methods do not accept 'raw' bson as a parameter (eg: insertOne and replaceOne).

      I've got 2 work-a-rounds for this:

      • Emulate these methods around with updateOne.
      • Generic the MongoCollection to BsonDocument instead.

      I much prefer if MongoCollection supports these method with Bson as a value, as update does.

      For your reference, what I suggest is adding:

      • MongoCollection<D>.insertOne(Bson document)
      • MongoCollection<D>.replaceOne(Bson filter, Bson replacement)
        etc.
        Similar to updateOne(Bson filter, Bson update).

      Looking through the code of MongoCollectionImpl, it seems internally the Pojo is rather quickly converted to Bson.

      Attachments

        Activity

          People

            jeff.yemin@mongodb.com Jeffrey Yemin
            jessevanhouten Jesse van Houten
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: