0

I am new to using mongo db - and trying to learn mongo template and db object and see how to do update and insert without writing the model classes for every documents.

I will have a lot documents to update [ multiple collections also]. I will get my input as JSON - and want to write service which can parse the json and do inserts and updates.

Can anyone please point me to some good links which i can read about this ?

Thanks much,

Mmenon
  • 61
  • 6
  • You are looking for this I think: [MongoDB Java Driver Tutorial](https://mongodb.github.io/mongo-java-driver/4.2/driver/). – prasad_ Jul 09 '21 at 02:24
  • thank you -i will check this - i dont really want to write model classes for all entities.. and looking for updating using json, by passing the collection .. – Mmenon Jul 09 '21 at 13:07
  • In such case use the `org.bson.Document` class (you will find this in the API docs from my earlier link); you can parse a JSON string to a `Document` instance and write to the collection. – prasad_ Jul 09 '21 at 13:11
  • thank you - can i use the parsing and do update also ? any samples to share ? – Mmenon Jul 09 '21 at 15:10
  • _"can i use the parsing and do update also ?"_ : You can try the collection's `replace` method. You can also try using the `mongoimport` command-line tool to import JSON documents into MongoDB. There is `--mode` option with values: insert, upsert, delete and merge. – prasad_ Jul 09 '21 at 15:40
  • trying to do in java if possible. – Mmenon Jul 09 '21 at 16:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234700/discussion-between-mmenon-and-prasad). – Mmenon Jul 09 '21 at 16:31

0 Answers0