今天我尝试$set
带有$db
的DBRef来收集。
但服务器说:“不是okForStorage”,所以操作失败。
PS。我的mongod
版本是2.2
{
"ts" : ISODate("2013-01-16T14:05:42.814Z"),
"op" : "update",
"ns" : "mydb.coll1",
"query" : {
"_id" : NumberLong("928686353793211381")
},
"updateobj" : {
"$set" : {
"ref" : {
"$db" : "db2",
"$ref" : "coll2",
"$id" : NumberLong("928686353793211381")
}
}
},
"nscanned" : 1,
"keyUpdates" : 0,
"numYield" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(0),
"w" : NumberLong(200)
},
"timeAcquiringMicros" : {
"r" : NumberLong(0),
"w" : NumberLong(5)
}
},
"exception" : "not okForStorage",
"exceptionCode" : 12527,
"millis" : 0,
"client" : "10.168.89.9",
"user" : ""
}
答案 0 :(得分:1)
根据docs,DBRef中字段的顺序很重要;因此您需要将ref
对象重新排序为:
"ref" : {
"$ref" : "coll2",
"$id" : NumberLong("928686353793211381"),
"$db" : "db2"
}