2021年4月6日星期二

Issue Updating a field that doesn't exist in MongoDB using F#

I have written a save function

let saveRecord(record: PostDataItem, coll: IMongoCollection<PostDataItem>, orderNumberToCheck: string) =       let filterDefinition = Builders<PostDataItem>.Filter.Eq((fun d -> d._id), record._id)      let  update = Builders<PostDataItem>.Update.Set((fun f -> f.orderNumberToCheck),orderNumberToCheck)      let options = new UpdateOptions(IsUpsert=true)      let result = coll.UpdateOne(filterDefinition, update, options)      result   

Unfortunately the result from MongoDB tells me that it found a match when trying to update, but it did not modify it ( matched=1, modified=0 ). The only unique thing about this is that the field "orderNumberToCheck" doesn't actually exist prior to this - but I assumed that upsert would take care of that. My type is below.

[<CLIMutable>]  type PostDataItem = {      _id: BsonObjectId      dateLodged: DateTime      productCode: string      productDescription: string      clientReference: string      manifestContract: string      client: string      quantity: string      unitPrice: string      gst: string      total: string      clientReference2: string      weight: string      reference1: string      ticketNumber: string      transactioncode: string      invoiceExplanationField1: string      invoiceExplanationField2: string      invoiceExplanationField3: string      invoiceExplanationField4: string      invoiceExplanationField5: string      invoiceExplanationField6: string      [<BsonDefaultValue(null)>]      orderNumberToCheck: string      [<BsonDefaultValue(null)>]      isUnique: Nullable<bool>      [<BsonDefaultValue(null)>]      expectedPrice: Nullable<decimal>  }  
https://stackoverflow.com/questions/66977840/issue-updating-a-field-that-doesnt-exist-in-mongodb-using-f April 07, 2021 at 07:40AM

没有评论:

发表评论