จะนำเข้า JSON ไปยัง MongoDB Atlas และตั้งค่าประเภทไฟล์จากฟังก์ชัน Realm ได้อย่างไร

ฉันกำลังพยายามนำเข้าข้อมูลด้วยรูปแบบ JSON ไปยัง Atlas ตามที่เป็นอยู่ ในกรณีส่วนใหญ่จะทำงานได้ตามที่คาดไว้ แต่ในบางกรณีค่าจะอยู่ในรูปแบบ ceil และนำเข้าเป็น Int แทนที่จะเป็น Double วิธีนี้จะป้องกันไม่ให้บันทึกเหล่านั้นถูกนำเข้าโดยการซิงค์:

MongoEncodingError Error - Apr 03 7:14:04+03:00
Error:

Failed to apply MongoDB change event to sync history
Source:

Error syncing MongoDB write
Logs:
[
  "Change Event Type: insert",
  "Namespace: public-data.previous-day-prices",
  "Partition: P",
  "Document ID: JAZZ",
  "Detailed Error: could not convert MongoDB value to Realm payload for { table: PreviousDayPriceRealmModel, path: close }, value=168 : cannot transform int value for non-int property of type double"
]

ฉันพยายามค้นหาวิธีแยกแยะประเภท แต่ไม่ได้กำหนดทั้ง NumberDecimal และ Decimal128 ในฟังก์ชัน Realm ดังนั้นดูเหมือนว่าวิธีเดียวคือเพิ่มข้อมูลก่อนแล้วจึงแก้ไขประเภทฟิลด์ แต่มันดูไม่ถูกต้อง . ฉันพลาดอะไรบางอย่างไปหรือเปล่า? ฉันเพิ่งเริ่มใช้ MongoDB, Realm Sync และ JS


person Anton Plebanovich    schedule 03.04.2021    source แหล่งที่มา


คำตอบ (1)


ไม่เป็นไร ฉัน ในที่สุดก็พบประเภทที่ต้องการ BSON.Double

json.doubleField = BSON.Double(json.doubleField);
person Anton Plebanovich    schedule 03.04.2021