亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

mongodb中$or和upsert兼容問題
PHPz
PHPz 2017-04-22 08:58:57
0
2
680

今天碰到一個問題,當(dāng)我在update數(shù)據(jù)的時候想使用upsert功能,發(fā)現(xiàn)插入的數(shù)據(jù)并沒有過濾條件中$or的部分,如下:

db.msg.update(
    {
        “type”: “u”,
        “$or”: [
            {“from”: 1, “to”: 2},
            {“from”: 2, “to”: 1}
        ]
    },
    {
        “$push”: {
            “message”: {
                “data”: “holla”,
                “status”: false,
                “time”: new Date()
            }
        }
    },
    true,
    true
);

本來希望的是:如果發(fā)現(xiàn)msg集合中如果沒有對應(yīng)文檔,則插入,例如上面的這條更新(假設(shè)當(dāng)前集合中不存在from:1,to:2的這個文檔),執(zhí)行完后msg集合中應(yīng)當(dāng)出現(xiàn)下面這個文檔:

{
    "from": 1,
    "to": 2,
    "type": "u",
    "message": [
        {
            “data”: “holla”,
            “status”: false,
            “time”: ISODate("2014-02-12T01:50:40.866Z")
        }
    ]
}

可實際情況是插入的數(shù)據(jù)中并不會包含$or部分的條件,請問有沒有解決方案?

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(2)
Ty80

$upsert currently (2.4) does not support $and and $or, but it is said that 2.6 supports it. See official issues:

  • $or paired with upsert does not create documents for each or clause
  • Insert from update (w/upsert:true) ignores $and equality fields
小葫蘆

upsert This method is inherently unreliable, and it is clearly written in the manual

Warning: To avoid inserting the same document more than once, only use upsert: true if the query field is uniquely indexed.

So you ignored me?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template