I made some changes to a field of a document and then write the DataFrame back to MongoDB using APPEND_MODE. The fields are updated successfully.However when I try to update some fields then after writing the DataFrame using save method the remaining fields of document disappears.
Hi luqman,
To clarify, you are able to update one field of a document successfully however when updating multiple fields the non-updated fields disappears ?
I’ve just tested this behaviour with environment: mongo-spark v1.1.0, Apache Spark v1.6.2, and MongoDB v3.2.x using ‘append’ mode and successfully updated multiple fields value of a dataframe:
MongoSpark.save(df.write.option("collection", "collNameToUpdate").mode("append"))
If you have further questions, could you provide the relevant information:
Your mongo-spark version
Your Apache-Spark version
Your MongoDB version
An example snippet code of the failing update
An example input/output documents showing the failed update operation
If any, error log or output.
Best regards,
Wan
A scenario could be load the data to dataframe……filterout some fields except _id …….and then save it using append……..the dataframe is replaced. I don’t want the other fields to disappear.
Hi luqman,
To clarify your case with an example, you have a document with fields fieldA
and fieldB
, with _id
field loaded into a dataframe via the connector. After filtering out fieldA
, update the value of fieldB
, and saving with append, the document in source is now only containing fieldB
and _id
.
If the above case description is correct, then there is currently an open tracking ticket SPARK-100 for this improvement. Please feel free to watch/upvote the ticket for updates.
However, if the above description is not what you’re referring to, could you please clarify further with some code steps and examples. For example, the original document, DataFrame, document after saving, etc.
Regards,
Wan.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/afee82e7-356f-459a-9127-22c9404367b8%40googlegroups.com.
{ "_id" : ObjectId("5aec54da78062173ca30f1bd"), "id" : 1, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1be"), "id" : 2, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1bf"), "id" : 3, "value" : 1 }
+--------------------------+---+
|_id |id |
+--------------------------+---+
|[5aec54da78062173ca30f1be]|4 |
+--------------------------+---+
val writeConfig = WriteConfig(Map("uri" -> s"mongodb://$host/$database.$table"))
MongoSpark.save(df1.write.option("replaceDocument", "false").mode("append"), writeConfig)
{ "_id" : ObjectId("5aec54da78062173ca30f1bd"), "id" : 1, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1be"), "id" : 4, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1bf"), "id" : 3, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1bd"), "id" : 1, "value" : 1 }
{ "_id" : ObjectId("5aec54da78062173ca30f1be"), "id" : 4 }
{ "_id" : ObjectId("5aec54da78062173ca30f1bf"), "id" : 3, "value" : 1 }
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/afee82e7-356f-459a-9127-22c9404367b8%40googlegroups.com.
val writeConfig = WriteConfig(Map("uri" -> s"mongodb://$host/$database.$table", "replaceDocument" -> "false"))
MongoSpark.save(data.write.mode("append"), writeConfig)
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/afee82e7-356f-459a-9127-22c9404367b8%40googlegroups.com.