Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
发布更新不包含';使用F在MongoDB中不存在#_Mongodb_F# - Fatal编程技术网

发布更新不包含';使用F在MongoDB中不存在#

发布更新不包含';使用F在MongoDB中不存在#,mongodb,f#,Mongodb,F#,我已经写了一个保存函数 let saveRecord(record: PostDataItem, coll: IMongoCollection<PostDataItem>, orderNumberToCheck: string) = let filterDefinition = Builders<PostDataItem>.Filter.Eq((fun d -> d._id), record._id) let update = Builders&

我已经写了一个保存函数

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 
let saveRecord(记录:PostDataItem,coll:IMongoCollection,orderNumberToCheck:string)=
让filterDefinition=Builders.Filter.Eq((fund->d.\u id),record.\u id)
让update=Builders.update.Set((f->f.orderNumberToCheck),orderNumberToCheck)
让选项=新的更新选项(IsUpsert=true)
让结果=coll.UpdateOne(过滤器定义、更新、选项)
结果
不幸的是,MongoDB的结果告诉我,它在尝试更新时找到了匹配项,但没有修改它(matched=1,modified=0)。唯一的独特之处是“orderNumberToCheck”字段在此之前并不存在,但我认为upsert会处理这个问题。我的类型如下

[<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>
}
[]
类型PostDataItem={
_id:BsonObjectId
日期:日期时间
产品代码:字符串
productDescription:字符串
clientReference:string
合同名称:字符串
客户端:字符串
数量:字符串
单价:字符串
商品及服务税:字符串
总计:字符串
clientReference2:字符串
重量:细绳
参考文献1:字符串
票号:字符串
transactioncode:字符串
invoiceExplanationField1:字符串
invoiceExplanationField2:字符串
invoiceExplanationField3:字符串
invoiceExplanationField4:字符串
invoiceExplanationField5:字符串
invoiceExplanationField6:字符串
[]
orderNumberToCheck:字符串
[]
isUnique:可为空
[]
预期价格:可为空
}

我无法复制此内容。在我的测试用例中,我得到matched=1和modified=1。代码中唯一看起来有点可疑的是,您已将
\u id
声明为
BsonObjectId
,而不是
ObjectId
。我甚至不知道区别是什么,但我看到的示例使用了
ObjectId
。然而,当我尝试使用相同的值第二次更新同一文档时,我确实得到了matched=1和modified=0,但我认为这是因为该文档已成功更新。你确定你的文档根本没有被更新吗?@brianberns谢谢。我用objected稍微重写了一下,它似乎起作用了。我注意到它返回了不止一条记录——我可能误解了更新的记录。非常感谢你抽出时间。