2016-09-08 12 views
0

Fooは私のMongoDBcollectionです。 あり、私は一つだけdocumentを持っている:流星。 MongoDB upsertエラー:TypeError:keypath.splitは関数ではありません。 ( 'keypath.split('。 ')'、 'keypath.split'は定義されていません)

{ 
    0: {code: "basic", caption: "basic", points: 100}, 
    1: {code: "gold", caption: "gold", points: 200}, 
    2: {code: "platinum", caption: "platinum", points: 300}, 
    3: {code: "diamond", caption: "diamond", points: 400}, 
    id: "PnpbhFi8m7NqZXRr6" 
} 

私はupsertにしようとしています、それは私が次のエラーが表示されます

TypeError: keypath.split is not a function. (In 'keypath.split('.')', 'keypath.split' is undefined) 

は、これは私のコードです:

const data = [ 
    { 
    "code": "basic", 
    "caption": "basic", 
    "points": 100 
    }, 
    { 
    "code": "gold", 
    "caption": "gold", 
    "points": 200 
    }, 
    { 
    "code": "platinum", 
    "caption": "platinum", 
    "points": 300 
    }, 
    { 
    "code": "diamond", 
    "caption": "diamond", 
    "points": 400 
    } 
]; 

const doc = Foo.findOne(); 
Foo.upsert(doc._id, { $set: data }); 

れる私間違い?

+0

は 'オブジェクトの配列または番号キーを使用して、ネストされたオブジェクトであるdata'持っているあなたの意図は使い? –

答えて

1

あなたは$setを間違って使用します。

Foo.update(doc._id, { 
    $set: { 
    4: data[0], 
    5: data[1], 
    6: data[2], 
    7: data[3], 
    } 
}); 

また、あなたがupsertを使用する必要はありません:あなたは$setにオブジェクトを渡す必要があります。 meteor docsupsert

Modify one or more documents in the collection, or insert one if no matching documents were found

が、あなたの文書が存在するので、upsertの必要がない、update

+0

ありがとう!あなたは私をたくさん助けました – Edgar

関連する問題